src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/SignExtendNode.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 |
23 |
24 |
24 |
25 package org.graalvm.compiler.nodes.calc; |
25 package org.graalvm.compiler.nodes.calc; |
26 |
26 |
27 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_1; |
27 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_1; |
|
28 import static org.graalvm.compiler.nodes.calc.BinaryArithmeticNode.getArithmeticOpTable; |
28 |
29 |
29 import jdk.vm.ci.code.CodeUtil; |
|
30 import org.graalvm.compiler.core.common.type.ArithmeticOpTable; |
30 import org.graalvm.compiler.core.common.type.ArithmeticOpTable; |
31 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.IntegerConvertOp; |
31 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.IntegerConvertOp; |
32 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.IntegerConvertOp.Narrow; |
32 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.IntegerConvertOp.Narrow; |
33 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.IntegerConvertOp.SignExtend; |
33 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.IntegerConvertOp.SignExtend; |
34 import org.graalvm.compiler.core.common.type.IntegerStamp; |
34 import org.graalvm.compiler.core.common.type.IntegerStamp; |
40 import org.graalvm.compiler.nodeinfo.NodeInfo; |
40 import org.graalvm.compiler.nodeinfo.NodeInfo; |
41 import org.graalvm.compiler.nodes.NodeView; |
41 import org.graalvm.compiler.nodes.NodeView; |
42 import org.graalvm.compiler.nodes.ValueNode; |
42 import org.graalvm.compiler.nodes.ValueNode; |
43 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; |
43 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; |
44 |
44 |
|
45 import jdk.vm.ci.code.CodeUtil; |
|
46 |
45 /** |
47 /** |
46 * The {@code SignExtendNode} converts an integer to a wider integer using sign extension. |
48 * The {@code SignExtendNode} converts an integer to a wider integer using sign extension. |
47 */ |
49 */ |
48 @NodeInfo(cycles = CYCLES_1) |
50 @NodeInfo(cycles = CYCLES_1) |
49 public final class SignExtendNode extends IntegerConvertNode<SignExtend, Narrow> { |
51 public final class SignExtendNode extends IntegerConvertNode<SignExtend, Narrow> { |
54 this(input, PrimitiveStamp.getBits(input.stamp(NodeView.DEFAULT)), resultBits); |
56 this(input, PrimitiveStamp.getBits(input.stamp(NodeView.DEFAULT)), resultBits); |
55 assert 0 < PrimitiveStamp.getBits(input.stamp(NodeView.DEFAULT)) && PrimitiveStamp.getBits(input.stamp(NodeView.DEFAULT)) <= resultBits; |
57 assert 0 < PrimitiveStamp.getBits(input.stamp(NodeView.DEFAULT)) && PrimitiveStamp.getBits(input.stamp(NodeView.DEFAULT)) <= resultBits; |
56 } |
58 } |
57 |
59 |
58 public SignExtendNode(ValueNode input, int inputBits, int resultBits) { |
60 public SignExtendNode(ValueNode input, int inputBits, int resultBits) { |
59 super(TYPE, ArithmeticOpTable::getSignExtend, ArithmeticOpTable::getNarrow, inputBits, resultBits, input); |
61 super(TYPE, getArithmeticOpTable(input).getSignExtend(), inputBits, resultBits, input); |
60 } |
62 } |
61 |
63 |
62 public static ValueNode create(ValueNode input, int resultBits, NodeView view) { |
64 public static ValueNode create(ValueNode input, int resultBits, NodeView view) { |
63 return create(input, PrimitiveStamp.getBits(input.stamp(view)), resultBits, view); |
65 return create(input, PrimitiveStamp.getBits(input.stamp(view)), resultBits, view); |
64 } |
66 } |
68 ValueNode synonym = findSynonym(signExtend, input, inputBits, resultBits, signExtend.foldStamp(inputBits, resultBits, input.stamp(view))); |
70 ValueNode synonym = findSynonym(signExtend, input, inputBits, resultBits, signExtend.foldStamp(inputBits, resultBits, input.stamp(view))); |
69 if (synonym != null) { |
71 if (synonym != null) { |
70 return synonym; |
72 return synonym; |
71 } |
73 } |
72 return canonical(null, input, inputBits, resultBits, view); |
74 return canonical(null, input, inputBits, resultBits, view); |
|
75 } |
|
76 |
|
77 @Override |
|
78 protected IntegerConvertOp<SignExtend> getOp(ArithmeticOpTable table) { |
|
79 return table.getSignExtend(); |
|
80 } |
|
81 |
|
82 @Override |
|
83 protected IntegerConvertOp<Narrow> getReverseOp(ArithmeticOpTable table) { |
|
84 return table.getNarrow(); |
73 } |
85 } |
74 |
86 |
75 @Override |
87 @Override |
76 public boolean isLossless() { |
88 public boolean isLossless() { |
77 return true; |
89 return true; |