# HG changeset patch # User Lukas Stadler # Date 1331743599 -3600 # Node ID f29e75070bb6d1a0d7aeae37de4502742c6e47b0 # Parent 3e21269ee9015cbcd38f59bebddc586cc2dbcfe9 experimental type storage/query infrastructure, part 2: type feedback diff -r 3e21269ee901 -r f29e75070bb6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardNode.java Wed Mar 14 17:42:41 2012 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardNode.java Wed Mar 14 17:46:39 2012 +0100 @@ -22,11 +22,13 @@ */ package com.oracle.graal.nodes; +import com.oracle.graal.graph.*; import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.spi.types.*; import com.oracle.graal.nodes.type.*; -public final class GuardNode extends FloatingNode implements Canonicalizable, LIRLowerable { +public final class GuardNode extends FloatingNode implements Canonicalizable, LIRLowerable, TypeFeedbackProvider, Node.IterableNodeType { @Input private BooleanNode condition; @Input(notDataflow = true) private FixedNode anchor; @@ -47,6 +49,11 @@ return condition; } + public void setCondition(BooleanNode x) { + updateUsages(condition, x); + condition = x; + } + public GuardNode(BooleanNode condition, FixedNode anchor) { super(StampFactory.illegal()); this.condition = condition; @@ -63,10 +70,24 @@ if (condition() instanceof ConstantNode) { ConstantNode c = (ConstantNode) condition(); if (c.asConstant().asBoolean()) { + if (!dependencies().isEmpty()) { + for (Node usage : usages()) { + if (usage instanceof ValueNode) { + ((ValueNode) usage).dependencies().addAll(dependencies()); + } + } + } this.replaceAtUsages(null); return null; } } return this; } + + @Override + public void typeFeedback(TypeFeedbackTool tool) { + if (condition instanceof ConditionalTypeFeedbackProvider) { + ((ConditionalTypeFeedbackProvider) condition).typeFeedback(tool); + } + } } diff -r 3e21269ee901 -r f29e75070bb6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerAddNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerAddNode.java Wed Mar 14 17:42:41 2012 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerAddNode.java Wed Mar 14 17:46:39 2012 +0100 @@ -26,9 +26,10 @@ import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.spi.types.*; @NodeInfo(shortName = "+") -public class IntegerAddNode extends IntegerArithmeticNode implements Canonicalizable, LIRLowerable { +public class IntegerAddNode extends IntegerArithmeticNode implements Canonicalizable, LIRLowerable, TypeFeedbackProvider { public IntegerAddNode(CiKind kind, ValueNode x, ValueNode y) { super(kind, x, y); @@ -93,4 +94,13 @@ } gen.setResult(this, gen.emitAdd(op1, op2)); } + + @Override + public void typeFeedback(TypeFeedbackTool tool) { + if (y().isConstant() && !x().isConstant()) { + tool.addScalar(this).setTranslated(y().asConstant(), tool.queryScalar(x())); + } else if (x().isConstant() && !y().isConstant()) { + tool.addScalar(this).setTranslated(x().asConstant(), tool.queryScalar(y())); + } + } } diff -r 3e21269ee901 -r f29e75070bb6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AccessIndexedNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AccessIndexedNode.java Wed Mar 14 17:42:41 2012 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AccessIndexedNode.java Wed Mar 14 17:46:39 2012 +0100 @@ -22,15 +22,17 @@ */ package com.oracle.graal.nodes.java; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.spi.types.*; +import com.oracle.graal.nodes.type.*; import com.oracle.max.cri.ci.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.type.*; /** * The {@code AccessIndexedNode} class is the base class of instructions that read or write * elements of an array. */ -public abstract class AccessIndexedNode extends AccessArrayNode { +public abstract class AccessIndexedNode extends AccessArrayNode implements TypeFeedbackProvider { @Input private ValueNode index; @Input private ValueNode length; @@ -67,4 +69,10 @@ public CiKind elementKind() { return elementType; } + + @Override + public void typeFeedback(TypeFeedbackTool tool) { + tool.addScalar(index()).constantBound(Condition.GE, CiConstant.INT_0); + tool.addScalar(index()).valueBound(Condition.LT, length, tool.queryScalar(length)); + } } diff -r 3e21269ee901 -r f29e75070bb6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java Wed Mar 14 17:42:41 2012 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java Wed Mar 14 17:46:39 2012 +0100 @@ -28,13 +28,15 @@ import com.oracle.max.cri.ri.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.spi.types.*; import com.oracle.graal.nodes.type.*; /** * The {@code NewArrayNode} class is the base of all instructions that allocate arrays. */ -public abstract class NewArrayNode extends FixedWithNextNode implements EscapeAnalyzable{ +public abstract class NewArrayNode extends FixedWithNextNode implements EscapeAnalyzable, TypeFeedbackProvider { @Input private ValueNode length; @@ -75,6 +77,12 @@ public abstract RiResolvedType elementType(); @Override + public void typeFeedback(TypeFeedbackTool tool) { + assert length.kind() == CiKind.Int; + tool.addScalar(length).constantBound(Condition.GE, CiConstant.INT_0); + } + + @Override public Map getDebugProperties() { Map properties = super.getDebugProperties(); properties.put("exactType", exactType()); diff -r 3e21269ee901 -r f29e75070bb6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewMultiArrayNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewMultiArrayNode.java Wed Mar 14 17:42:41 2012 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewMultiArrayNode.java Wed Mar 14 17:46:39 2012 +0100 @@ -22,17 +22,20 @@ */ package com.oracle.graal.nodes.java; +import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.spi.types.*; import com.oracle.graal.nodes.type.*; /** * The {@code NewMultiArrayNode} represents an allocation of a multi-dimensional object * array. */ -public final class NewMultiArrayNode extends FixedWithNextNode implements LIRLowerable { +public final class NewMultiArrayNode extends FixedWithNextNode implements LIRLowerable, TypeFeedbackProvider { @Input private final NodeInputList dimensions; @Data private final RiResolvedType type; @@ -67,4 +70,12 @@ public RiResolvedType type() { return type; } + + @Override + public void typeFeedback(TypeFeedbackTool tool) { + for (ValueNode length : dimensions) { + assert length.kind() == CiKind.Int; + tool.addScalar(length).constantBound(Condition.GE, CiConstant.INT_0); + } + } } diff -r 3e21269ee901 -r f29e75070bb6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/types/TypeFeedbackProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/types/TypeFeedbackProvider.java Wed Mar 14 17:46:39 2012 +0100 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.nodes.spi.types; + +public interface TypeFeedbackProvider { + + void typeFeedback(TypeFeedbackTool tool); +} diff -r 3e21269ee901 -r f29e75070bb6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/types/TypeFeedbackTool.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/types/TypeFeedbackTool.java Wed Mar 14 17:46:39 2012 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.nodes.spi.types; + +import com.oracle.max.cri.ri.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; + +public interface TypeFeedbackTool { + + ScalarTypeFeedbackTool addScalar(ValueNode value); + + ObjectTypeFeedbackTool addObject(ValueNode value); + + ScalarTypeQuery queryScalar(ValueNode value); + + ObjectTypeQuery queryObject(ValueNode value); + + RiRuntime runtime(); + + TypeFeedbackTool negate(); + +}