src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/UnaryArithmeticNode.java
changeset 58533 46b0b7fe255c
parent 52910 583fd71c47d6
equal deleted inserted replaced
58532:b4f2e13d20ea 58533:46b0b7fe255c
     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.
    22  */
    22  */
    23 
    23 
    24 
    24 
    25 package org.graalvm.compiler.nodes.calc;
    25 package org.graalvm.compiler.nodes.calc;
    26 
    26 
    27 import java.io.Serializable;
    27 import static org.graalvm.compiler.nodes.calc.BinaryArithmeticNode.getArithmeticOpTable;
    28 import java.util.function.Function;
       
    29 
    28 
    30 import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
    29 import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
    31 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.UnaryOp;
    30 import org.graalvm.compiler.core.common.type.ArithmeticOpTable.UnaryOp;
    32 import org.graalvm.compiler.core.common.type.Stamp;
    31 import org.graalvm.compiler.core.common.type.Stamp;
    33 import org.graalvm.compiler.graph.NodeClass;
    32 import org.graalvm.compiler.graph.NodeClass;
    42 @NodeInfo
    41 @NodeInfo
    43 public abstract class UnaryArithmeticNode<OP> extends UnaryNode implements ArithmeticOperation, ArithmeticLIRLowerable {
    42 public abstract class UnaryArithmeticNode<OP> extends UnaryNode implements ArithmeticOperation, ArithmeticLIRLowerable {
    44 
    43 
    45     @SuppressWarnings("rawtypes") public static final NodeClass<UnaryArithmeticNode> TYPE = NodeClass.create(UnaryArithmeticNode.class);
    44     @SuppressWarnings("rawtypes") public static final NodeClass<UnaryArithmeticNode> TYPE = NodeClass.create(UnaryArithmeticNode.class);
    46 
    45 
    47     protected interface SerializableUnaryFunction<T> extends Function<ArithmeticOpTable, UnaryOp<T>>, Serializable {
    46     protected UnaryArithmeticNode(NodeClass<? extends UnaryArithmeticNode<OP>> c, UnaryOp<OP> opForStampComputation, ValueNode value) {
       
    47         super(c, opForStampComputation.foldStamp(value.stamp(NodeView.DEFAULT)), value);
    48     }
    48     }
    49 
    49 
    50     protected final SerializableUnaryFunction<OP> getOp;
    50     protected abstract UnaryOp<OP> getOp(ArithmeticOpTable table);
    51 
       
    52     protected UnaryArithmeticNode(NodeClass<? extends UnaryArithmeticNode<OP>> c, SerializableUnaryFunction<OP> getOp, ValueNode value) {
       
    53         super(c, getOp.apply(ArithmeticOpTable.forStamp(value.stamp(NodeView.DEFAULT))).foldStamp(value.stamp(NodeView.DEFAULT)), value);
       
    54         this.getOp = getOp;
       
    55     }
       
    56 
    51 
    57     protected final UnaryOp<OP> getOp(ValueNode forValue) {
    52     protected final UnaryOp<OP> getOp(ValueNode forValue) {
    58         return getOp.apply(ArithmeticOpTable.forStamp(forValue.stamp(NodeView.DEFAULT)));
    53         return getOp(getArithmeticOpTable(forValue));
    59     }
    54     }
    60 
    55 
    61     @Override
    56     @Override
    62     public final UnaryOp<OP> getArithmeticOp() {
    57     public final UnaryOp<OP> getArithmeticOp() {
    63         return getOp(getValue());
    58         return getOp(getValue());