src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/BinaryArithmeticNode.java
changeset 58533 46b0b7fe255c
parent 54084 84f10bbf993f
child 58877 aec7bf35d6f5
equal deleted inserted replaced
58532:b4f2e13d20ea 58533:46b0b7fe255c
     1 /*
     1 /*
     2  * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2009, 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.
    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.nodeinfo.NodeSize.SIZE_1;
    28 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1;
    29 
    29 
    30 import java.io.Serializable;
       
    31 import java.util.function.Function;
       
    32 
       
    33 import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
    30 import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
    34 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp;
    31 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp;
    35 import org.graalvm.compiler.core.common.type.IntegerStamp;
    32 import org.graalvm.compiler.core.common.type.IntegerStamp;
    36 import org.graalvm.compiler.core.common.type.Stamp;
    33 import org.graalvm.compiler.core.common.type.Stamp;
    37 import org.graalvm.compiler.debug.GraalError;
    34 import org.graalvm.compiler.debug.GraalError;
    56 @NodeInfo(cycles = CYCLES_1, size = SIZE_1)
    53 @NodeInfo(cycles = CYCLES_1, size = SIZE_1)
    57 public abstract class BinaryArithmeticNode<OP> extends BinaryNode implements ArithmeticOperation, ArithmeticLIRLowerable, Canonicalizable.Binary<ValueNode> {
    54 public abstract class BinaryArithmeticNode<OP> extends BinaryNode implements ArithmeticOperation, ArithmeticLIRLowerable, Canonicalizable.Binary<ValueNode> {
    58 
    55 
    59     @SuppressWarnings("rawtypes") public static final NodeClass<BinaryArithmeticNode> TYPE = NodeClass.create(BinaryArithmeticNode.class);
    56     @SuppressWarnings("rawtypes") public static final NodeClass<BinaryArithmeticNode> TYPE = NodeClass.create(BinaryArithmeticNode.class);
    60 
    57 
    61     protected interface SerializableBinaryFunction<T> extends Function<ArithmeticOpTable, BinaryOp<T>>, Serializable {
    58     protected BinaryArithmeticNode(NodeClass<? extends BinaryArithmeticNode<OP>> c, BinaryOp<OP> opForStampComputation, ValueNode x, ValueNode y) {
    62     }
    59         super(c, opForStampComputation.foldStamp(x.stamp(NodeView.DEFAULT), y.stamp(NodeView.DEFAULT)), x, y);
    63 
    60     }
    64     protected final SerializableBinaryFunction<OP> getOp;
    61 
    65 
    62     public static ArithmeticOpTable getArithmeticOpTable(ValueNode forValue) {
    66     protected BinaryArithmeticNode(NodeClass<? extends BinaryArithmeticNode<OP>> c, SerializableBinaryFunction<OP> getOp, ValueNode x, ValueNode y) {
    63         return ArithmeticOpTable.forStamp(forValue.stamp(NodeView.DEFAULT));
    67         super(c, getOp.apply(ArithmeticOpTable.forStamp(x.stamp(NodeView.DEFAULT))).foldStamp(x.stamp(NodeView.DEFAULT), y.stamp(NodeView.DEFAULT)), x, y);
    64     }
    68         this.getOp = getOp;
    65 
    69     }
    66     protected abstract BinaryOp<OP> getOp(ArithmeticOpTable table);
    70 
    67 
    71     protected final BinaryOp<OP> getOp(ValueNode forX, ValueNode forY) {
    68     protected final BinaryOp<OP> getOp(ValueNode forX, ValueNode forY) {
    72         ArithmeticOpTable table = ArithmeticOpTable.forStamp(forX.stamp(NodeView.DEFAULT));
    69         ArithmeticOpTable table = getArithmeticOpTable(forX);
    73         assert table.equals(ArithmeticOpTable.forStamp(forY.stamp(NodeView.DEFAULT)));
    70         assert table.equals(getArithmeticOpTable(forY));
    74         return getOp.apply(table);
    71         return getOp(table);
    75     }
    72     }
    76 
    73 
    77     @Override
    74     @Override
    78     public final BinaryOp<OP> getArithmeticOp() {
    75     public final BinaryOp<OP> getArithmeticOp() {
    79         return getOp(getX(), getY());
    76         return getOp(getX(), getY());