< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/BinaryMathIntrinsicNode.java

Print this page




   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  */
  23 
  24 
  25 package org.graalvm.compiler.replacements.nodes;
  26 
  27 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN;
  28 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1;


  29 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  30 import org.graalvm.compiler.core.common.type.FloatStamp;
  31 import org.graalvm.compiler.core.common.type.PrimitiveStamp;
  32 import org.graalvm.compiler.core.common.type.Stamp;
  33 import org.graalvm.compiler.core.common.type.StampFactory;
  34 import org.graalvm.compiler.debug.GraalError;
  35 import org.graalvm.compiler.graph.NodeClass;
  36 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  37 import org.graalvm.compiler.lir.gen.ArithmeticLIRGeneratorTool;
  38 import org.graalvm.compiler.nodeinfo.NodeInfo;
  39 import org.graalvm.compiler.nodes.ConstantNode;
  40 import org.graalvm.compiler.nodes.NodeView;
  41 import org.graalvm.compiler.nodes.ValueNode;
  42 import org.graalvm.compiler.nodes.calc.BinaryNode;
  43 import org.graalvm.compiler.nodes.calc.FloatDivNode;
  44 import org.graalvm.compiler.nodes.calc.MulNode;
  45 import org.graalvm.compiler.nodes.calc.SqrtNode;
  46 import org.graalvm.compiler.nodes.spi.ArithmeticLIRLowerable;
  47 import org.graalvm.compiler.nodes.spi.Lowerable;
  48 import org.graalvm.compiler.nodes.spi.LoweringTool;
  49 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  50 
  51 import jdk.vm.ci.meta.JavaKind;
  52 import jdk.vm.ci.meta.Value;
  53 
  54 @NodeInfo(nameTemplate = "MathIntrinsic#{p#operation/s}", cycles = CYCLES_UNKNOWN, size = SIZE_1)
  55 public final class BinaryMathIntrinsicNode extends BinaryNode implements ArithmeticLIRLowerable, Lowerable {
  56 
  57     public static final NodeClass<BinaryMathIntrinsicNode> TYPE = NodeClass.create(BinaryMathIntrinsicNode.class);
  58     protected final BinaryOperation operation;
  59 
  60     public enum BinaryOperation {
  61         POW(new ForeignCallDescriptor("arithmeticPow", double.class, double.class, double.class));
  62 
  63         public final ForeignCallDescriptor foreignCallDescriptor;
  64 
  65         BinaryOperation(ForeignCallDescriptor foreignCallDescriptor) {
  66             this.foreignCallDescriptor = foreignCallDescriptor;
  67         }
  68     }
  69 
  70     public BinaryOperation getOperation() {
  71         return operation;
  72     }


  89 
  90     @Override
  91     public Stamp foldStamp(Stamp stampX, Stamp stampY) {
  92         return stamp(NodeView.DEFAULT);
  93     }
  94 
  95     protected BinaryMathIntrinsicNode(ValueNode forX, ValueNode forY, BinaryOperation op) {
  96         super(TYPE, StampFactory.forKind(JavaKind.Double), forX, forY);
  97         assert forX.stamp(NodeView.DEFAULT) instanceof FloatStamp && PrimitiveStamp.getBits(forX.stamp(NodeView.DEFAULT)) == 64;
  98         assert forY.stamp(NodeView.DEFAULT) instanceof FloatStamp && PrimitiveStamp.getBits(forY.stamp(NodeView.DEFAULT)) == 64;
  99         this.operation = op;
 100     }
 101 
 102     @Override
 103     public void lower(LoweringTool tool) {
 104         tool.getLowerer().lower(this, tool);
 105     }
 106 
 107     @Override
 108     public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) {

 109         Value xValue = nodeValueMap.operand(getX());
 110         Value yValue = nodeValueMap.operand(getY());
 111         Value result;
 112         switch (getOperation()) {
 113             case POW:
 114                 result = gen.emitMathPow(xValue, yValue);
 115                 break;
 116             default:
 117                 throw GraalError.shouldNotReachHere();
 118         }
 119         nodeValueMap.setResult(this, result);
 120     }
 121 
 122     @Override
 123     public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
 124         NodeView view = NodeView.from(tool);
 125         ValueNode c = tryConstantFold(forX, forY, getOperation());
 126         if (c != null) {
 127             return c;
 128         }




   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  */
  23 
  24 
  25 package org.graalvm.compiler.replacements.nodes;
  26 
  27 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN;
  28 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1;
  29 
  30 import jdk.vm.ci.meta.Value;
  31 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  32 import org.graalvm.compiler.core.common.type.FloatStamp;
  33 import org.graalvm.compiler.core.common.type.PrimitiveStamp;
  34 import org.graalvm.compiler.core.common.type.Stamp;
  35 import org.graalvm.compiler.core.common.type.StampFactory;
  36 import org.graalvm.compiler.debug.GraalError;
  37 import org.graalvm.compiler.graph.NodeClass;
  38 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  39 import org.graalvm.compiler.lir.gen.ArithmeticLIRGeneratorTool;
  40 import org.graalvm.compiler.nodeinfo.NodeInfo;
  41 import org.graalvm.compiler.nodes.ConstantNode;
  42 import org.graalvm.compiler.nodes.NodeView;
  43 import org.graalvm.compiler.nodes.ValueNode;
  44 import org.graalvm.compiler.nodes.calc.BinaryNode;
  45 import org.graalvm.compiler.nodes.calc.FloatDivNode;
  46 import org.graalvm.compiler.nodes.calc.MulNode;
  47 import org.graalvm.compiler.nodes.calc.SqrtNode;
  48 import org.graalvm.compiler.nodes.spi.ArithmeticLIRLowerable;
  49 import org.graalvm.compiler.nodes.spi.Lowerable;
  50 import org.graalvm.compiler.nodes.spi.LoweringTool;

  51 
  52 import jdk.vm.ci.meta.JavaKind;
  53 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  54 
  55 @NodeInfo(nameTemplate = "MathIntrinsic#{p#operation/s}", cycles = CYCLES_UNKNOWN, size = SIZE_1)
  56 public final class BinaryMathIntrinsicNode extends BinaryNode implements ArithmeticLIRLowerable, Lowerable {
  57 
  58     public static final NodeClass<BinaryMathIntrinsicNode> TYPE = NodeClass.create(BinaryMathIntrinsicNode.class);
  59     protected final BinaryOperation operation;
  60 
  61     public enum BinaryOperation {
  62         POW(new ForeignCallDescriptor("arithmeticPow", double.class, double.class, double.class));
  63 
  64         public final ForeignCallDescriptor foreignCallDescriptor;
  65 
  66         BinaryOperation(ForeignCallDescriptor foreignCallDescriptor) {
  67             this.foreignCallDescriptor = foreignCallDescriptor;
  68         }
  69     }
  70 
  71     public BinaryOperation getOperation() {
  72         return operation;
  73     }


  90 
  91     @Override
  92     public Stamp foldStamp(Stamp stampX, Stamp stampY) {
  93         return stamp(NodeView.DEFAULT);
  94     }
  95 
  96     protected BinaryMathIntrinsicNode(ValueNode forX, ValueNode forY, BinaryOperation op) {
  97         super(TYPE, StampFactory.forKind(JavaKind.Double), forX, forY);
  98         assert forX.stamp(NodeView.DEFAULT) instanceof FloatStamp && PrimitiveStamp.getBits(forX.stamp(NodeView.DEFAULT)) == 64;
  99         assert forY.stamp(NodeView.DEFAULT) instanceof FloatStamp && PrimitiveStamp.getBits(forY.stamp(NodeView.DEFAULT)) == 64;
 100         this.operation = op;
 101     }
 102 
 103     @Override
 104     public void lower(LoweringTool tool) {
 105         tool.getLowerer().lower(this, tool);
 106     }
 107 
 108     @Override
 109     public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) {
 110         // We can only reach here in the math stubs
 111         Value xValue = nodeValueMap.operand(getX());
 112         Value yValue = nodeValueMap.operand(getY());
 113         Value result;
 114         switch (getOperation()) {
 115             case POW:
 116                 result = gen.emitMathPow(xValue, yValue);
 117                 break;
 118             default:
 119                 throw GraalError.shouldNotReachHere();
 120         }
 121         nodeValueMap.setResult(this, result);
 122     }
 123 
 124     @Override
 125     public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
 126         NodeView view = NodeView.from(tool);
 127         ValueNode c = tryConstantFold(forX, forY, getOperation());
 128         if (c != null) {
 129             return c;
 130         }


< prev index next >