annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java @ 18845:f57d86eb036f

removed Node factory methods
author Doug Simon <doug.simon@oracle.com>
date Mon, 12 Jan 2015 20:39:04 +0100
parents 290dc460feb3
children ec0733b5a90a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
4 *
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
8 *
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
13 * accompanied this code).
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
14 *
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
18 *
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
21 * questions.
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
22 */
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.nodes.calc;
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
24
17344
98e60bdf6d05 Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
25 import com.oracle.graal.compiler.common.type.*;
17419
83c3dd41ca64 Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents: 17418
diff changeset
26 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.IntegerConvertOp.Narrow;
83c3dd41ca64 Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents: 17418
diff changeset
27 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.IntegerConvertOp.SignExtend;
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.graph.spi.*;
15299
60406b8d6ad1 Move ArithmeticLIRGenerator to graal.lir (errors).
Josef Eisl <josef.eisl@jku.at>
parents: 15261
diff changeset
29 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
30 import com.oracle.graal.nodeinfo.*;
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.nodes.*;
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.nodes.spi.*;
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
33
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
34 /**
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
35 * The {@code NarrowNode} converts an integer to a narrower integer.
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@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
17419
83c3dd41ca64 Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents: 17418
diff changeset
38 public class NarrowNode extends IntegerConvertNode<Narrow, SignExtend> {
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
39
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
40 public NarrowNode(ValueNode input, int resultBits) {
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
41 this(input, PrimitiveStamp.getBits(input.stamp()), resultBits);
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
42 assert 0 < resultBits && resultBits <= PrimitiveStamp.getBits(input.stamp());
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
43 }
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
44
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
45 public NarrowNode(ValueNode input, int inputBits, int resultBits) {
18646
290dc460feb3 use better types to simplify instantiation of Serializable lambdas
Doug Simon <doug.simon@oracle.com>
parents: 18644
diff changeset
46 super(ArithmeticOpTable::getNarrow, ArithmeticOpTable::getSignExtend, inputBits, resultBits, input);
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
47 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
48
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
49 @Override
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
50 public boolean isLossless() {
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
51 return false;
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
52 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
53
14122
2a7d7da912e1 Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents: 14026
diff changeset
54 @Override
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
55 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
17344
98e60bdf6d05 Use ArithmeticOpTable for primitive convert operations.
Roland Schatz <roland.schatz@oracle.com>
parents: 17196
diff changeset
56 ValueNode ret = super.canonical(tool, forValue);
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
57 if (ret != this) {
14025
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
58 return ret;
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
59 }
9738280055ce Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 14000
diff changeset
60
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
61 if (forValue instanceof NarrowNode) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
62 // zzzzzzzz yyyyxxxx -(narrow)-> yyyyxxxx -(narrow)-> xxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
63 // ==> zzzzzzzz yyyyxxxx -(narrow)-> xxxx
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
64 NarrowNode other = (NarrowNode) forValue;
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
65 return new NarrowNode(other.getValue(), other.getInputBits(), getResultBits());
16216
388b787a5fe6 implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
66 } else if (forValue instanceof IntegerConvertNode) {
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
67 // SignExtendNode or ZeroExtendNode
17419
83c3dd41ca64 Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents: 17418
diff changeset
68 IntegerConvertNode<?, ?> other = (IntegerConvertNode<?, ?>) forValue;
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
69 if (getResultBits() == other.getInputBits()) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
70 // xxxx -(extend)-> yyyy xxxx -(narrow)-> xxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
71 // ==> no-op
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15911
diff changeset
72 return other.getValue();
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
73 } else if (getResultBits() < other.getInputBits()) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
74 // yyyyxxxx -(extend)-> zzzzzzzz yyyyxxxx -(narrow)-> xxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
75 // ==> yyyyxxxx -(narrow)-> xxxx
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
76 return new NarrowNode(other.getValue(), other.getInputBits(), getResultBits());
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
77 } else {
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
78 if (other instanceof SignExtendNode) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
79 // sxxx -(sign-extend)-> ssssssss sssssxxx -(narrow)-> sssssxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
80 // ==> sxxx -(sign-extend)-> sssssxxx
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
81 return new SignExtendNode(other.getValue(), other.getInputBits(), getResultBits());
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
82 } else if (other instanceof ZeroExtendNode) {
14026
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
83 // xxxx -(zero-extend)-> 00000000 00000xxx -(narrow)-> 0000xxxx
57a2d00ef771 Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents: 14025
diff changeset
84 // ==> xxxx -(zero-extend)-> 0000xxxx
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18646
diff changeset
85 return new ZeroExtendNode(other.getValue(), other.getInputBits(), getResultBits());
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
86 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
87 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
88 }
14122
2a7d7da912e1 Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents: 14026
diff changeset
89 return this;
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
90 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
91
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
92 @Override
15130
ec22234bde0d Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents: 14950
diff changeset
93 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) {
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15911
diff changeset
94 builder.setResult(this, gen.emitNarrow(builder.operand(getValue()), getResultBits()));
14000
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
95 }
958c99d0790c Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
96 }