Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NegateNode.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 |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
2 * Copyright (c) 2009, 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 |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
25 import com.oracle.graal.api.meta.*; |
15193
96bb07a5d667
Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents:
15132
diff
changeset
|
26 import com.oracle.graal.compiler.common.*; |
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:
15193
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.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
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 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 * The {@code NegateNode} node negates its operand. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 */ |
16811
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16216
diff
changeset
|
37 @NodeInfo |
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16216
diff
changeset
|
38 public class NegateNode extends UnaryNode implements ArithmeticLIRLowerable, NarrowableArithmeticNode { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5606
diff
changeset
|
40 @Override |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5606
diff
changeset
|
41 public boolean inferStamp() { |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
42 return updateStamp(StampTool.negate(getValue().stamp())); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5606
diff
changeset
|
43 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5606
diff
changeset
|
44 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 /** |
5606
5ad40c8ba3ed
add StampFactory.negate(IntegerStamp), use it for NegateNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5425
diff
changeset
|
46 * Creates new NegateNode instance. |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
47 * |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
48 * @param value the instruction producing the value that is input to this instruction |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 */ |
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
|
50 public static NegateNode create(ValueNode value) { |
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
|
51 return new NegateNodeGen(value); |
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
|
52 } |
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
|
53 |
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
|
54 protected NegateNode(ValueNode value) { |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
55 super(StampTool.negate(value.stamp()), value); |
3733
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 |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
58 public Constant evalConst(Constant... inputs) { |
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
59 assert inputs.length == 1; |
12460 | 60 Constant constant = inputs[0]; |
61 switch (constant.getKind()) { | |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
62 case Int: |
12460 | 63 return Constant.forInt(-(constant.asInt())); |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
64 case Long: |
12460 | 65 return Constant.forLong(-(constant.asLong())); |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
66 case Float: |
12460 | 67 return Constant.forFloat(-(constant.asFloat())); |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
68 case Double: |
12460 | 69 return Constant.forDouble(-(constant.asDouble())); |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
70 default: |
12460 | 71 throw GraalInternalError.shouldNotReachHere("unknown kind " + constant.getKind()); |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
72 } |
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
73 } |
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11289
diff
changeset
|
74 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 @Override |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
76 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
77 if (forValue.isConstant()) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
78 return ConstantNode.forConstant(evalConst(forValue.asConstant()), null); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 } |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
80 if (forValue instanceof NegateNode) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
81 return ((NegateNode) forValue).getValue(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
82 } |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
83 if (forValue instanceof IntegerSubNode) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
84 IntegerSubNode sub = (IntegerSubNode) forValue; |
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
|
85 return IntegerSubNode.create(sub.getY(), sub.getX()); |
9448
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7530
diff
changeset
|
86 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 return this; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
88 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
90 @Override |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
91 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) { |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
92 builder.setResult(this, gen.emitNegate(builder.operand(getValue()))); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
93 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
94 } |