Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java @ 18124:689092d5cf44
Store explicit input bit width in IntegerConvertNode.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Mon, 20 Oct 2014 16:26:05 +0200 |
parents | 45b45f902bed |
children | 47263ffe47bd |
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:
16822
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 */ |
16822
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 |
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
|
40 public static NarrowNode create(ValueNode input, int resultBits) { |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
41 int inputBits = PrimitiveStamp.getBits(input.stamp()); |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
42 assert 0 < resultBits && resultBits <= inputBits; |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
43 return create(input, inputBits, resultBits); |
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
|
44 } |
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
|
45 |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
46 public static NarrowNode create(ValueNode input, int inputBits, int resultBits) { |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
47 return new NarrowNode(input, inputBits, resultBits); |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
48 } |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
49 |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
50 protected NarrowNode(ValueNode input, int inputBits, int resultBits) { |
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
51 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
|
52 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
53 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
54 @Override |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
55 public boolean isLossless() { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
56 return false; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
57 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
58 |
14122
2a7d7da912e1
Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents:
14026
diff
changeset
|
59 @Override |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
60 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
|
61 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
|
62 if (ret != this) { |
14025
9738280055ce
Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
63 return ret; |
9738280055ce
Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
64 } |
9738280055ce
Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
65 |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
66 if (forValue instanceof NarrowNode) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
67 // zzzzzzzz yyyyxxxx -(narrow)-> yyyyxxxx -(narrow)-> xxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
68 // ==> zzzzzzzz yyyyxxxx -(narrow)-> xxxx |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
69 NarrowNode other = (NarrowNode) forValue; |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
70 return NarrowNode.create(other.getValue(), other.getInputBits(), getResultBits()); |
16216
388b787a5fe6
implement Canonicalizable.Unary in the UnaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16156
diff
changeset
|
71 } 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
|
72 // SignExtendNode or ZeroExtendNode |
17419
83c3dd41ca64
Simplify ArithmeticOpTable implementation and make it type safe.
Roland Schatz <roland.schatz@oracle.com>
parents:
17418
diff
changeset
|
73 IntegerConvertNode<?, ?> other = (IntegerConvertNode<?, ?>) forValue; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
74 if (getResultBits() == other.getInputBits()) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
75 // xxxx -(extend)-> yyyy xxxx -(narrow)-> xxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
76 // ==> no-op |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15911
diff
changeset
|
77 return other.getValue(); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
78 } else if (getResultBits() < other.getInputBits()) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
79 // yyyyxxxx -(extend)-> zzzzzzzz yyyyxxxx -(narrow)-> xxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
80 // ==> yyyyxxxx -(narrow)-> xxxx |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
81 return NarrowNode.create(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 { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
83 if (other instanceof SignExtendNode) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
84 // sxxx -(sign-extend)-> ssssssss sssssxxx -(narrow)-> sssssxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
85 // ==> sxxx -(sign-extend)-> sssssxxx |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
86 return SignExtendNode.create(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
|
87 } else if (other instanceof ZeroExtendNode) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
88 // xxxx -(zero-extend)-> 00000000 00000xxx -(narrow)-> 0000xxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
89 // ==> xxxx -(zero-extend)-> 0000xxxx |
18124
689092d5cf44
Store explicit input bit width in IntegerConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
90 return ZeroExtendNode.create(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
|
91 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
92 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
93 } |
14122
2a7d7da912e1
Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents:
14026
diff
changeset
|
94 return this; |
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 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
97 @Override |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
98 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) { |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15911
diff
changeset
|
99 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
|
100 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
101 } |