1 /* 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 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 */ 23 24 25 package org.graalvm.compiler.nodes; 26 27 import org.graalvm.compiler.core.common.type.Stamp; 28 import org.graalvm.compiler.graph.Graph; 29 import org.graalvm.compiler.graph.Node; 30 import org.graalvm.compiler.graph.NodeClass; 31 import org.graalvm.compiler.graph.spi.Canonicalizable; 32 import org.graalvm.compiler.nodeinfo.NodeInfo; 33 import org.graalvm.compiler.nodes.spi.LIRLowerable; 34 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; 35 36 import jdk.vm.ci.meta.TriState; 37 38 @NodeInfo 39 public abstract class BinaryOpLogicNode extends LogicNode implements LIRLowerable, Canonicalizable.Binary<ValueNode> { 40 41 public static final NodeClass<BinaryOpLogicNode> TYPE = NodeClass.create(BinaryOpLogicNode.class); 42 @Input protected ValueNode x; 43 @Input protected ValueNode y; 44 45 @Override getX()46 public ValueNode getX() { 47 return x; 48 } 49 50 @Override getY()51 public ValueNode getY() { 52 return y; 53 } 54 BinaryOpLogicNode(NodeClass<? extends BinaryOpLogicNode> c, ValueNode x, ValueNode y)55 public BinaryOpLogicNode(NodeClass<? extends BinaryOpLogicNode> c, ValueNode x, ValueNode y) { 56 super(c); 57 assert x != null && y != null; 58 this.x = x; 59 this.y = y; 60 } 61 62 @Override verify()63 public boolean verify() { 64 return super.verify(); 65 } 66 67 @Override generate(NodeLIRBuilderTool gen)68 public void generate(NodeLIRBuilderTool gen) { 69 } 70 71 /** 72 * Ensure a canonical ordering of inputs for commutative nodes to improve GVN results. Order the 73 * inputs by increasing {@link Node#id} and call {@link Graph#findDuplicate(Node)} on the node 74 * if it's currently in a graph. 75 * 76 * @return the original node or another node with the same inputs, ignoring ordering. 77 */ 78 @SuppressWarnings("deprecation") maybeCommuteInputs()79 public LogicNode maybeCommuteInputs() { 80 assert this instanceof BinaryCommutative; 81 if (!y.isConstant() && (x.isConstant() || x.getId() > y.getId())) { 82 ValueNode tmp = x; 83 x = y; 84 y = tmp; 85 if (graph() != null) { 86 // See if this node already exists 87 LogicNode duplicate = graph().findDuplicate(this); 88 if (duplicate != null) { 89 return duplicate; 90 } 91 } 92 } 93 return this; 94 } 95 getSucceedingStampForX(boolean negated, Stamp xStamp, Stamp yStamp)96 public abstract Stamp getSucceedingStampForX(boolean negated, Stamp xStamp, Stamp yStamp); 97 getSucceedingStampForY(boolean negated, Stamp xStamp, Stamp yStamp)98 public abstract Stamp getSucceedingStampForY(boolean negated, Stamp xStamp, Stamp yStamp); 99 tryFold(Stamp xStamp, Stamp yStamp)100 public abstract TriState tryFold(Stamp xStamp, Stamp yStamp); 101 } 102