< prev index next >

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

Print this page




  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 static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_0;
  28 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_0;
  29 
  30 import org.graalvm.compiler.core.common.type.AbstractPointerStamp;
  31 import org.graalvm.compiler.core.common.type.ObjectStamp;
  32 import org.graalvm.compiler.core.common.type.Stamp;
  33 import org.graalvm.compiler.core.common.type.StampFactory;
  34 import org.graalvm.compiler.core.common.type.TypeReference;

  35 import org.graalvm.compiler.graph.IterableNodeType;
  36 import org.graalvm.compiler.graph.Node;
  37 import org.graalvm.compiler.graph.NodeClass;
  38 import org.graalvm.compiler.graph.spi.Canonicalizable;
  39 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  40 import org.graalvm.compiler.nodeinfo.NodeInfo;
  41 import org.graalvm.compiler.nodes.extended.GuardingNode;
  42 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  43 import org.graalvm.compiler.nodes.memory.ReadNode;
  44 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  45 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  46 import org.graalvm.compiler.nodes.spi.ValueProxy;
  47 import org.graalvm.compiler.nodes.spi.Virtualizable;
  48 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
  49 import org.graalvm.compiler.nodes.type.StampTool;
  50 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
  51 
  52 import jdk.vm.ci.meta.JavaKind;
  53 import jdk.vm.ci.meta.ResolvedJavaMethod;
  54 import jdk.vm.ci.meta.ResolvedJavaType;


  83     }
  84 
  85     public PiNode(ValueNode object, Stamp stamp) {
  86         this(object, stamp, null);
  87     }
  88 
  89     public PiNode(ValueNode object, Stamp stamp, ValueNode guard) {
  90         this(TYPE, object, stamp, (GuardingNode) guard);
  91     }
  92 
  93     public PiNode(ValueNode object, ValueNode guard) {
  94         this(object, AbstractPointerStamp.pointerNonNull(object.stamp(NodeView.DEFAULT)), guard);
  95     }
  96 
  97     public PiNode(ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
  98         this(object, StampFactory.object(exactType ? TypeReference.createExactTrusted(toType) : TypeReference.createWithoutAssumptions(toType),
  99                         nonNull || StampTool.isPointerNonNull(object.stamp(NodeView.DEFAULT))));
 100     }
 101 
 102     public static ValueNode create(ValueNode object, Stamp stamp) {
 103         ValueNode value = canonical(object, stamp, null);
 104         if (value != null) {
 105             return value;
 106         }
 107         return new PiNode(object, stamp);
 108     }
 109 
 110     public static ValueNode create(ValueNode object, Stamp stamp, ValueNode guard) {
 111         ValueNode value = canonical(object, stamp, (GuardingNode) guard);
 112         if (value != null) {
 113             return value;
 114         }
 115         return new PiNode(object, stamp, guard);
 116     }
 117 
 118     public static ValueNode create(ValueNode object, ValueNode guard) {
 119         Stamp stamp = AbstractPointerStamp.pointerNonNull(object.stamp(NodeView.DEFAULT));
 120         ValueNode value = canonical(object, stamp, (GuardingNode) guard);
 121         if (value != null) {
 122             return value;
 123         }
 124         return new PiNode(object, stamp, guard);
 125     }
 126 
 127     @SuppressWarnings("unused")
 128     public static boolean intrinsify(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode object, ValueNode guard) {
 129         Stamp stamp = AbstractPointerStamp.pointerNonNull(object.stamp(NodeView.DEFAULT));
 130         ValueNode value = canonical(object, stamp, (GuardingNode) guard);
 131         if (value == null) {
 132             value = new PiNode(object, stamp, guard);
 133         }
 134         b.push(JavaKind.Object, b.append(value));
 135         return true;
 136     }
 137 
 138     @SuppressWarnings("unused")
 139     public static boolean intrinsify(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
 140         Stamp stamp = StampFactory.object(exactType ? TypeReference.createExactTrusted(toType) : TypeReference.createWithoutAssumptions(toType),
 141                         nonNull || StampTool.isPointerNonNull(object.stamp(NodeView.DEFAULT)));
 142         ValueNode value = canonical(object, stamp, null);
 143         if (value == null) {
 144             value = new PiNode(object, stamp);
 145         }
 146         b.push(JavaKind.Object, b.append(value));
 147         return true;
 148     }
 149 
 150     public final Stamp piStamp() {
 151         return piStamp;
 152     }
 153 
 154     public void strengthenPiStamp(Stamp newPiStamp) {
 155         assert this.piStamp.join(newPiStamp).equals(newPiStamp) : "stamp can only improve";
 156         this.piStamp = newPiStamp;
 157     }
 158 
 159     @Override
 160     public void generate(NodeLIRBuilderTool generator) {
 161         if (generator.hasOperand(object)) {
 162             generator.setResult(this, generator.operand(object));
 163         }
 164     }
 165 
 166     @Override
 167     public boolean inferStamp() {
 168         return updateStamp(computeStamp());
 169     }
 170 
 171     private Stamp computeStamp() {
 172         return piStamp.improveWith(object().stamp(NodeView.DEFAULT));
 173     }
 174 
 175     @Override
 176     public void virtualize(VirtualizerTool tool) {
 177         ValueNode alias = tool.getAlias(object());
 178         if (alias instanceof VirtualObjectNode) {
 179             VirtualObjectNode virtual = (VirtualObjectNode) alias;
 180             if (StampTool.typeOrNull(this) != null && StampTool.typeOrNull(this).isAssignableFrom(virtual.type())) {

 181                 tool.replaceWithVirtual(virtual);


 182             }
 183         }
 184     }
 185 
 186     public static ValueNode canonical(ValueNode object, Stamp stamp, GuardingNode guard) {
 187         // Use most up to date stamp.
 188         Stamp computedStamp = stamp.improveWith(object.stamp(NodeView.DEFAULT));
 189 
 190         // The pi node does not give any additional information => skip it.
 191         if (computedStamp.equals(object.stamp(NodeView.DEFAULT))) {
 192             return object;
 193         }
 194 
 195         if (guard == null) {
 196             // Try to merge the pi node with a load node.
 197             if (object instanceof ReadNode && !object.hasMoreThanOneUsage()) {
 198                 ReadNode readNode = (ReadNode) object;
 199                 readNode.setStamp(readNode.stamp(NodeView.DEFAULT).improveWith(stamp));
 200                 return readNode;
 201             }
 202         } else {
 203             for (Node n : guard.asNode().usages()) {
 204                 if (n instanceof PiNode) {
 205                     PiNode otherPi = (PiNode) n;

 206                     if (object == otherPi.object() && computedStamp.equals(otherPi.stamp(NodeView.DEFAULT))) {
 207                         /*
 208                          * Two PiNodes with the same guard and same result, so return the one with
 209                          * the more precise piStamp.
 210                          */
 211                         Stamp newStamp = stamp.join(otherPi.piStamp);
 212                         if (newStamp.equals(otherPi.piStamp)) {
 213                             return otherPi;
 214                         }
 215                     }
 216                 }
 217             }
 218         }
 219         return null;
 220     }
 221 
 222     @Override
 223     public Node canonical(CanonicalizerTool tool) {
 224         Node value = canonical(object(), stamp(NodeView.DEFAULT), getGuard());
 225         if (value != null) {
 226             return value;
 227         }
 228         return this;
 229     }
 230 
 231     @Override
 232     public ValueNode getOriginalNode() {
 233         return object;
 234     }
 235 
 236     public void setOriginalNode(ValueNode newNode) {
 237         this.updateUsages(object, newNode);
 238         this.object = newNode;
 239         assert piStamp.isCompatible(object.stamp(NodeView.DEFAULT)) : "New object stamp not compatible to piStamp";
 240     }
 241 
 242     /**
 243      * Casts an object to have an exact, non-null stamp representing {@link Class}.
 244      */




  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 static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_0;
  28 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_0;
  29 
  30 import org.graalvm.compiler.core.common.type.AbstractPointerStamp;
  31 import org.graalvm.compiler.core.common.type.ObjectStamp;
  32 import org.graalvm.compiler.core.common.type.Stamp;
  33 import org.graalvm.compiler.core.common.type.StampFactory;
  34 import org.graalvm.compiler.core.common.type.TypeReference;
  35 import org.graalvm.compiler.debug.DebugContext;
  36 import org.graalvm.compiler.graph.IterableNodeType;
  37 import org.graalvm.compiler.graph.Node;
  38 import org.graalvm.compiler.graph.NodeClass;
  39 import org.graalvm.compiler.graph.spi.Canonicalizable;
  40 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  41 import org.graalvm.compiler.nodeinfo.NodeInfo;
  42 import org.graalvm.compiler.nodes.extended.GuardingNode;
  43 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  44 import org.graalvm.compiler.nodes.memory.ReadNode;
  45 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  46 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  47 import org.graalvm.compiler.nodes.spi.ValueProxy;
  48 import org.graalvm.compiler.nodes.spi.Virtualizable;
  49 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
  50 import org.graalvm.compiler.nodes.type.StampTool;
  51 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
  52 
  53 import jdk.vm.ci.meta.JavaKind;
  54 import jdk.vm.ci.meta.ResolvedJavaMethod;
  55 import jdk.vm.ci.meta.ResolvedJavaType;


  84     }
  85 
  86     public PiNode(ValueNode object, Stamp stamp) {
  87         this(object, stamp, null);
  88     }
  89 
  90     public PiNode(ValueNode object, Stamp stamp, ValueNode guard) {
  91         this(TYPE, object, stamp, (GuardingNode) guard);
  92     }
  93 
  94     public PiNode(ValueNode object, ValueNode guard) {
  95         this(object, AbstractPointerStamp.pointerNonNull(object.stamp(NodeView.DEFAULT)), guard);
  96     }
  97 
  98     public PiNode(ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
  99         this(object, StampFactory.object(exactType ? TypeReference.createExactTrusted(toType) : TypeReference.createWithoutAssumptions(toType),
 100                         nonNull || StampTool.isPointerNonNull(object.stamp(NodeView.DEFAULT))));
 101     }
 102 
 103     public static ValueNode create(ValueNode object, Stamp stamp) {
 104         ValueNode value = canonical(object, stamp, null, null);
 105         if (value != null) {
 106             return value;
 107         }
 108         return new PiNode(object, stamp);
 109     }
 110 
 111     public static ValueNode create(ValueNode object, Stamp stamp, ValueNode guard) {
 112         ValueNode value = canonical(object, stamp, (GuardingNode) guard, null);
 113         if (value != null) {
 114             return value;
 115         }
 116         return new PiNode(object, stamp, guard);
 117     }
 118 
 119     public static ValueNode create(ValueNode object, ValueNode guard) {
 120         Stamp stamp = AbstractPointerStamp.pointerNonNull(object.stamp(NodeView.DEFAULT));
 121         ValueNode value = canonical(object, stamp, (GuardingNode) guard, null);
 122         if (value != null) {
 123             return value;
 124         }
 125         return new PiNode(object, stamp, guard);
 126     }
 127 
 128     @SuppressWarnings("unused")
 129     public static boolean intrinsify(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode object, ValueNode guard) {
 130         Stamp stamp = AbstractPointerStamp.pointerNonNull(object.stamp(NodeView.DEFAULT));
 131         ValueNode value = canonical(object, stamp, (GuardingNode) guard, null);
 132         if (value == null) {
 133             value = new PiNode(object, stamp, guard);
 134         }
 135         b.push(JavaKind.Object, b.append(value));
 136         return true;
 137     }
 138 
 139     @SuppressWarnings("unused")
 140     public static boolean intrinsify(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
 141         Stamp stamp = StampFactory.object(exactType ? TypeReference.createExactTrusted(toType) : TypeReference.createWithoutAssumptions(toType),
 142                         nonNull || StampTool.isPointerNonNull(object.stamp(NodeView.DEFAULT)));
 143         ValueNode value = canonical(object, stamp, null, null);
 144         if (value == null) {
 145             value = new PiNode(object, stamp);
 146         }
 147         b.push(JavaKind.Object, b.append(value));
 148         return true;
 149     }
 150 
 151     public final Stamp piStamp() {
 152         return piStamp;
 153     }
 154 
 155     public void strengthenPiStamp(Stamp newPiStamp) {
 156         assert this.piStamp.join(newPiStamp).equals(newPiStamp) : "stamp can only improve";
 157         this.piStamp = newPiStamp;
 158     }
 159 
 160     @Override
 161     public void generate(NodeLIRBuilderTool generator) {
 162         if (generator.hasOperand(object)) {
 163             generator.setResult(this, generator.operand(object));
 164         }
 165     }
 166 
 167     @Override
 168     public boolean inferStamp() {
 169         return updateStamp(computeStamp());
 170     }
 171 
 172     private Stamp computeStamp() {
 173         return piStamp.improveWith(object().stamp(NodeView.DEFAULT));
 174     }
 175 
 176     @Override
 177     public void virtualize(VirtualizerTool tool) {
 178         ValueNode alias = tool.getAlias(object());
 179         if (alias instanceof VirtualObjectNode) {
 180             VirtualObjectNode virtual = (VirtualObjectNode) alias;
 181             ResolvedJavaType type = StampTool.typeOrNull(this, tool.getMetaAccess());
 182             if (type != null && type.isAssignableFrom(virtual.type())) {
 183                 tool.replaceWithVirtual(virtual);
 184             } else {
 185                 tool.getDebug().log(DebugContext.INFO_LEVEL, "could not virtualize Pi because of type mismatch: %s %s vs %s", this, type, virtual.type());
 186             }
 187         }
 188     }
 189 
 190     public static ValueNode canonical(ValueNode object, Stamp stamp, GuardingNode guard, PiNode self) {
 191         // Use most up to date stamp.
 192         Stamp computedStamp = stamp.improveWith(object.stamp(NodeView.DEFAULT));
 193 
 194         // The pi node does not give any additional information => skip it.
 195         if (computedStamp.equals(object.stamp(NodeView.DEFAULT))) {
 196             return object;
 197         }
 198 
 199         if (guard == null) {
 200             // Try to merge the pi node with a load node.
 201             if (object instanceof ReadNode && !object.hasMoreThanOneUsage()) {
 202                 ReadNode readNode = (ReadNode) object;
 203                 readNode.setStamp(readNode.stamp(NodeView.DEFAULT).improveWith(stamp));
 204                 return readNode;
 205             }
 206         } else {
 207             for (Node n : guard.asNode().usages()) {
 208                 if (n instanceof PiNode && n != self) {
 209                     PiNode otherPi = (PiNode) n;
 210                     assert otherPi.guard == guard;
 211                     if (object == otherPi.object() && computedStamp.equals(otherPi.stamp(NodeView.DEFAULT))) {
 212                         /*
 213                          * Two PiNodes with the same guard and same result, so return the one with
 214                          * the more precise piStamp.
 215                          */
 216                         Stamp newStamp = stamp.join(otherPi.piStamp);
 217                         if (newStamp.equals(otherPi.piStamp)) {
 218                             return otherPi;
 219                         }
 220                     }
 221                 }
 222             }
 223         }
 224         return null;
 225     }
 226 
 227     @Override
 228     public Node canonical(CanonicalizerTool tool) {
 229         Node value = canonical(object(), piStamp(), getGuard(), this);
 230         if (value != null) {
 231             return value;
 232         }
 233         return this;
 234     }
 235 
 236     @Override
 237     public ValueNode getOriginalNode() {
 238         return object;
 239     }
 240 
 241     public void setOriginalNode(ValueNode newNode) {
 242         this.updateUsages(object, newNode);
 243         this.object = newNode;
 244         assert piStamp.isCompatible(object.stamp(NodeView.DEFAULT)) : "New object stamp not compatible to piStamp";
 245     }
 246 
 247     /**
 248      * Casts an object to have an exact, non-null stamp representing {@link Class}.
 249      */


< prev index next >