Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/OrNode.java @ 15198:2c0cfbf454b5
Move LIRTypeTool and Stamp to graal.compiler.common.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Thu, 17 Apr 2014 17:28:20 +0200 |
parents | ec22234bde0d |
children | 60406b8d6ad1 |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
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.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
27 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
|
28 import com.oracle.graal.graph.spi.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
29 import com.oracle.graal.nodes.*; |
14707
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
30 import com.oracle.graal.nodes.extended.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
31 import com.oracle.graal.nodes.spi.*; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5621
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 = "|") |
11289
2ad1435489d1
Use ArithmeticLIRGenerator in arithmetic nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
11265
diff
changeset
|
35 public final class OrNode extends BitLogicNode implements Canonicalizable { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
37 public OrNode(Stamp stamp, ValueNode x, ValueNode y) { |
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
38 super(stamp, x, y); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 @Override |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5621
diff
changeset
|
42 public boolean inferStamp() { |
11265 | 43 return updateStamp(StampTool.or(x().stamp(), y().stamp())); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5621
diff
changeset
|
44 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5621
diff
changeset
|
45 |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5621
diff
changeset
|
46 @Override |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
47 public Constant evalConst(Constant... inputs) { |
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
48 assert inputs.length == 2; |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
49 return Constant.forPrimitiveInt(PrimitiveStamp.getBits(stamp()), inputs[0].asLong() | inputs[1].asLong()); |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
50 } |
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
51 |
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
52 @Override |
11880
9a747d8e0d0f
broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11289
diff
changeset
|
53 public Node canonical(CanonicalizerTool tool) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 if (x() == y()) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 return x(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 if (x().isConstant() && !y().isConstant()) { |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
58 return graph().unique(new OrNode(stamp(), y(), x())); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 if (x().isConstant()) { |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
61 return ConstantNode.forPrimitive(stamp(), evalConst(x().asConstant(), y().asConstant()), graph()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 } else if (y().isConstant()) { |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
63 long rawY = y().asConstant().asLong(); |
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
64 long mask = IntegerStamp.defaultMask(PrimitiveStamp.getBits(stamp())); |
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
65 if ((rawY & mask) == mask) { |
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
66 return ConstantNode.forIntegerStamp(stamp(), mask, graph()); |
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
67 } |
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
68 if ((rawY & mask) == 0) { |
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
69 return x(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
70 } |
5621
b0f511b40eee
Add BinaryNode.reassociate to do generic +, -, *, &, |, ^ reassociation, use it for canoncialization. Will be used to reassociate loop invariants.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5540
diff
changeset
|
71 return BinaryNode.reassociate(this, ValueNode.isConstantPredicate()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
72 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 return this; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
74 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 @Override |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
77 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) { |
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
78 builder.setResult(this, gen.emitOr(builder.operand(x()), builder.operand(y()))); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 } |
14707
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
80 |
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
81 @Override |
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
82 public boolean generate(MemoryArithmeticLIRLowerer gen, Access access) { |
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
83 Value result = gen.emitOrMemory(x(), y(), access); |
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
84 if (result != null) { |
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
85 gen.setResult(this, result); |
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
86 } |
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
87 return result != null; |
6ce6c4ccba8f
initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14024
diff
changeset
|
88 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 } |