43972
|
1 |
/*
|
58533
|
2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
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
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.nodes.calc;
|
|
26 |
|
46459
|
27 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_32;
|
46393
|
28 |
|
43972
|
29 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
|
48190
|
30 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp;
|
43972
|
31 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Rem;
|
48190
|
32 |
import org.graalvm.compiler.core.common.type.Stamp;
|
43972
|
33 |
import org.graalvm.compiler.graph.NodeClass;
|
|
34 |
import org.graalvm.compiler.lir.gen.ArithmeticLIRGeneratorTool;
|
|
35 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
48190
|
36 |
import org.graalvm.compiler.nodes.ConstantNode;
|
|
37 |
import org.graalvm.compiler.nodes.NodeView;
|
43972
|
38 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
39 |
import org.graalvm.compiler.nodes.spi.Lowerable;
|
|
40 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
|
41 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
|
42 |
|
46459
|
43 |
@NodeInfo(shortName = "%", cycles = CYCLES_32/* div */)
|
43972
|
44 |
public class RemNode extends BinaryArithmeticNode<Rem> implements Lowerable {
|
|
45 |
|
|
46 |
public static final NodeClass<RemNode> TYPE = NodeClass.create(RemNode.class);
|
|
47 |
|
48190
|
48 |
protected RemNode(ValueNode x, ValueNode y) {
|
43972
|
49 |
this(TYPE, x, y);
|
|
50 |
}
|
|
51 |
|
|
52 |
protected RemNode(NodeClass<? extends RemNode> c, ValueNode x, ValueNode y) {
|
58533
|
53 |
super(c, getArithmeticOpTable(x).getRem(), x, y);
|
43972
|
54 |
}
|
|
55 |
|
48190
|
56 |
public static ValueNode create(ValueNode forX, ValueNode forY, NodeView view) {
|
|
57 |
BinaryOp<Rem> op = ArithmeticOpTable.forStamp(forX.stamp(view)).getRem();
|
|
58 |
Stamp stamp = op.foldStamp(forX.stamp(view), forY.stamp(view));
|
|
59 |
ConstantNode tryConstantFold = tryConstantFold(op, forX, forY, stamp, view);
|
|
60 |
if (tryConstantFold != null) {
|
|
61 |
return tryConstantFold;
|
|
62 |
}
|
|
63 |
return new RemNode(forX, forY);
|
|
64 |
}
|
|
65 |
|
43972
|
66 |
@Override
|
58533
|
67 |
protected BinaryOp<Rem> getOp(ArithmeticOpTable table) {
|
|
68 |
return table.getRem();
|
|
69 |
}
|
|
70 |
|
|
71 |
@Override
|
43972
|
72 |
public void lower(LoweringTool tool) {
|
|
73 |
tool.getLowerer().lower(this, tool);
|
|
74 |
}
|
|
75 |
|
|
76 |
@Override
|
|
77 |
public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) {
|
|
78 |
nodeValueMap.setResult(this, gen.emitRem(nodeValueMap.operand(getX()), nodeValueMap.operand(getY()), null));
|
|
79 |
}
|
|
80 |
}
|