Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NarrowNode.java @ 15911:03e09ed7039d
Use correct stamp when creating ConstantNode.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Mon, 26 May 2014 16:16:47 +0200 |
parents | 3a6dffce5158 |
children | 0993768dfc8e |
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 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
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:
15131
diff
changeset
|
26 import com.oracle.graal.compiler.common.type.*; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.graal.graph.*; |
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.*; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.nodes.*; |
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.spi.*; |
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.type.*; |
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 */ |
14122
2a7d7da912e1
Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents:
14026
diff
changeset
|
37 public class NarrowNode extends IntegerConvertNode { |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
38 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
39 public NarrowNode(ValueNode input, int resultBits) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
40 super(StampTool.narrowingConversion(input.stamp(), resultBits), input, resultBits); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
41 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
42 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
43 public static long narrow(long value, int resultBits) { |
15911
03e09ed7039d
Use correct stamp when creating ConstantNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
15413
diff
changeset
|
44 long ret = value & IntegerStamp.defaultMask(resultBits); |
03e09ed7039d
Use correct stamp when creating ConstantNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
15413
diff
changeset
|
45 return SignExtendNode.signExtend(ret, resultBits); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
46 } |
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 @Override |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
49 public Constant convert(Constant c) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
50 return Constant.forPrimitiveInt(getResultBits(), narrow(c.asLong(), getResultBits())); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
51 } |
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 @Override |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
54 public Constant reverse(Constant input) { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
15130
diff
changeset
|
55 long result = SignExtendNode.signExtend(input.asLong(), getResultBits()); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
56 return Constant.forPrimitiveInt(getInputBits(), result); |
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 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
59 @Override |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
60 public boolean isLossless() { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
61 return false; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
62 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
63 |
14122
2a7d7da912e1
Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents:
14026
diff
changeset
|
64 @Override |
2a7d7da912e1
Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents:
14026
diff
changeset
|
65 public Node canonical(CanonicalizerTool tool) { |
14025
9738280055ce
Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
66 ValueNode ret = canonicalConvert(); |
9738280055ce
Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
67 if (ret != null) { |
9738280055ce
Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
68 return ret; |
9738280055ce
Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
69 } |
9738280055ce
Reduce bit width of integer operations where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
70 |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
71 if (getInput() instanceof NarrowNode) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
72 // zzzzzzzz yyyyxxxx -(narrow)-> yyyyxxxx -(narrow)-> xxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
73 // ==> zzzzzzzz yyyyxxxx -(narrow)-> xxxx |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
74 NarrowNode other = (NarrowNode) getInput(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
75 return graph().unique(new NarrowNode(other.getInput(), getResultBits())); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
76 } else if (getInput() instanceof IntegerConvertNode) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
77 // SignExtendNode or ZeroExtendNode |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
78 IntegerConvertNode other = (IntegerConvertNode) getInput(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
79 if (getResultBits() == other.getInputBits()) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
80 // xxxx -(extend)-> yyyy xxxx -(narrow)-> xxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
81 // ==> no-op |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
82 return other.getInput(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
83 } else if (getResultBits() < other.getInputBits()) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
84 // yyyyxxxx -(extend)-> zzzzzzzz yyyyxxxx -(narrow)-> xxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
85 // ==> yyyyxxxx -(narrow)-> xxxx |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
86 return graph().unique(new NarrowNode(other.getInput(), getResultBits())); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
87 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
88 if (other instanceof SignExtendNode) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
89 // sxxx -(sign-extend)-> ssssssss sssssxxx -(narrow)-> sssssxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
90 // ==> sxxx -(sign-extend)-> sssssxxx |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
91 return graph().unique(new SignExtendNode(other.getInput(), getResultBits())); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
92 } else if (other instanceof ZeroExtendNode) { |
14026
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
93 // xxxx -(zero-extend)-> 00000000 00000xxx -(narrow)-> 0000xxxx |
57a2d00ef771
Source comments in integer conversion nodes.
Roland Schatz <roland.schatz@oracle.com>
parents:
14025
diff
changeset
|
94 // ==> xxxx -(zero-extend)-> 0000xxxx |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
95 return graph().unique(new ZeroExtendNode(other.getInput(), getResultBits())); |
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 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
98 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
99 |
14122
2a7d7da912e1
Don't narrow NarrowableArithmetic by default.
Roland Schatz <roland.schatz@oracle.com>
parents:
14026
diff
changeset
|
100 return this; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
101 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
102 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
103 @Override |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
104 public boolean inferStamp() { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
105 return updateStamp(StampTool.narrowingConversion(getInput().stamp(), getResultBits())); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
106 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
107 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
108 @Override |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
109 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
|
110 builder.setResult(this, gen.emitNarrow(builder.operand(getInput()), getResultBits())); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
111 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
112 } |