Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NotNode.java @ 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
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 15 Aug 2014 11:34:38 +0200 |
parents | 5d468add216f |
children | 06c15e88d383 |
rev | line source |
---|---|
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
1 /* |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
2 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
4 * |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
8 * |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
14 * |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
18 * |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
21 * questions. |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
22 */ |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.nodes.calc; |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
24 |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
25 import com.oracle.graal.api.meta.*; |
15261
882f4cb7cfcf
Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15132
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.*; |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.nodes.*; |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.nodes.spi.*; |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.type.*; |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
33 |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
34 /** |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
35 * Binary negation of long or integer values. |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
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 NotNode extends UnaryNode implements ArithmeticLIRLowerable, NarrowableArithmeticNode { |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
39 |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
40 @Override |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
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.not(getValue().stamp())); |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
43 } |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
44 |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11355
diff
changeset
|
45 @Override |
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11355
diff
changeset
|
46 public Constant evalConst(Constant... inputs) { |
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11355
diff
changeset
|
47 assert inputs.length == 1; |
14024
34c07ef28bc9
Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11883
diff
changeset
|
48 return Constant.forPrimitiveInt(PrimitiveStamp.getBits(stamp()), ~inputs[0].asLong()); |
11851
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11355
diff
changeset
|
49 } |
04b039d82e86
Simplify constant folding.
Roland Schatz <roland.schatz@oracle.com>
parents:
11355
diff
changeset
|
50 |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
51 /** |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
52 * 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
|
53 * |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
54 * @param x the instruction producing the value that is input to this instruction |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
55 */ |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
56 public NotNode(ValueNode x) { |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
57 super(StampTool.not(x.stamp()), x); |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
58 } |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
59 |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
60 @Override |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
61 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
62 if (forValue.isConstant()) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
63 return ConstantNode.forConstant(evalConst(forValue.asConstant()), null); |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
64 } |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
65 if (forValue instanceof NotNode) { |
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
66 return ((NotNode) forValue).getValue(); |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
67 } |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
68 return this; |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
69 } |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
70 |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
71 @Override |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
72 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) { |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
73 builder.setResult(this, gen.emitNot(builder.operand(getValue()))); |
11355
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
74 } |
01269a181628
add bitwise "not" operation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
75 } |