From 36e1422be1aab6d701584becb9afd57e62b1974e Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Wed, 9 Nov 2016 13:54:05 +0100 Subject: [PATCH] ValueProfiles in specials + few other places --- .../builtin/base/infix/SpecialsUtils.java | 6 +++++- .../r/nodes/builtin/base/infix/Subscript.java | 18 +++++++++--------- .../r/nodes/builtin/base/infix/Subset.java | 1 + .../access/vector/CachedExtractVectorNode.java | 1 + .../access/vector/CachedReplaceVectorNode.java | 3 +++ .../r/nodes/function/ClassHierarchyNode.java | 7 +++---- .../function/WrapDefaultArgumentNode.java | 2 +- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java index c513f62c7b..7618a1d5e3 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/SpecialsUtils.java @@ -24,6 +24,7 @@ package com.oracle.truffle.r.nodes.builtin.base.infix; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; +import com.oracle.truffle.api.profiles.ValueProfile; import com.oracle.truffle.r.nodes.function.ClassHierarchyNode; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.data.RList; @@ -49,7 +50,10 @@ class SpecialsUtils { */ abstract static class SubscriptSpecialCommon extends RNode { - protected static boolean isValidIndex(RAbstractVector vector, int index) { + protected final ValueProfile vectorClassProfile = ValueProfile.createClassProfile(); + + protected boolean isValidIndex(RAbstractVector vector, int index) { + vector = vectorClassProfile.profile(vector); return index >= 1 && index <= vector.getLength(); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java index 3a88c5ec74..ed74d6b51b 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subscript.java @@ -71,33 +71,33 @@ abstract class SubscriptSpecialBase extends SubscriptSpecialCommon { } @Specialization(guards = {"simpleVector(vector)", "isValidIndex(vector, index)"}) - protected static int access(RAbstractIntVector vector, int index) { - return vector.getDataAt(index - 1); + protected int access(RAbstractIntVector vector, int index) { + return vectorClassProfile.profile(vector).getDataAt(index - 1); } @Specialization(guards = {"simpleVector(vector)", "isValidIndex(vector, index)"}) - protected static double access(RAbstractDoubleVector vector, int index) { - return vector.getDataAt(index - 1); + protected double access(RAbstractDoubleVector vector, int index) { + return vectorClassProfile.profile(vector).getDataAt(index - 1); } @Specialization(guards = {"simpleVector(vector)", "isValidIndex(vector, index)"}) - protected static String access(RAbstractStringVector vector, int index) { - return vector.getDataAt(index - 1); + protected String access(RAbstractStringVector vector, int index) { + return vectorClassProfile.profile(vector).getDataAt(index - 1); } @Specialization(guards = {"simpleVector(vector)", "isValidDoubleIndex(vector, index)"}) protected int access(RAbstractIntVector vector, double index) { - return vector.getDataAt(toIndex(index) - 1); + return vectorClassProfile.profile(vector).getDataAt(toIndex(index) - 1); } @Specialization(guards = {"simpleVector(vector)", "isValidDoubleIndex(vector, index)"}) protected double access(RAbstractDoubleVector vector, double index) { - return vector.getDataAt(toIndex(index) - 1); + return vectorClassProfile.profile(vector).getDataAt(toIndex(index) - 1); } @Specialization(guards = {"simpleVector(vector)", "isValidDoubleIndex(vector, index)"}) protected String access(RAbstractStringVector vector, double index) { - return vector.getDataAt(toIndex(index) - 1); + return vectorClassProfile.profile(vector).getDataAt(toIndex(index) - 1); } @SuppressWarnings("unused") diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java index 09f0694fc7..4b3166024d 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/infix/Subset.java @@ -59,6 +59,7 @@ abstract class SubsetSpecial extends SubscriptSpecialBase { @Override protected boolean simpleVector(RAbstractVector vector) { + vector = vectorClassProfile.profile(vector); return super.simpleVector(vector) && vector.getNames(attrProfiles) == null; } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedExtractVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedExtractVectorNode.java index f42f5c7b72..67a858a2e7 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedExtractVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedExtractVectorNode.java @@ -68,6 +68,7 @@ final class CachedExtractVectorNode extends CachedVectorNode { private final VectorLengthProfile vectorLengthProfile = VectorLengthProfile.create(); private final RAttributeProfiles vectorNamesProfile = RAttributeProfiles.create(); + private final ValueProfile vectorClassProfile = ValueProfile.createClassProfile(); @Child private WriteIndexedVectorNode writeVectorNode; @Child private PositionsCheckNode positionsCheckNode; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java index e9c34ebf32..f536233486 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java @@ -88,6 +88,8 @@ final class CachedReplaceVectorNode extends CachedVectorNode { private final ConditionProfile emptyReplacementProfile = ConditionProfile.createBinaryProfile(); private final ConditionProfile completeVectorProfile = ConditionProfile.createBinaryProfile(); + private final ValueProfile vectorTypeProfile = ValueProfile.createClassProfile(); + private final RType valueType; private final RType castType; private final boolean updatePositionNames; @@ -262,6 +264,7 @@ final class CachedReplaceVectorNode extends CachedVectorNode { // resizing/materializing 'vector', it will be marked as 'temporary' and its refCount // incremented during the assignment step. + vector = vectorTypeProfile.profile(vector); vectorLength = targetLengthProfile.profile(vector.getLength()); if (mode.isSubset()) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ClassHierarchyNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ClassHierarchyNode.java index 5b53a47551..31056fa27f 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ClassHierarchyNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ClassHierarchyNode.java @@ -122,13 +122,12 @@ public abstract class ClassHierarchyNode extends UnaryNode { @Cached("createClassProfile()") ValueProfile argProfile) { RAttributes attributes; - RAttributable profiledArg; if (attrStorageProfile.profile(arg instanceof RAttributeStorage)) { // Note: the seemingly unnecessary cast is here to ensure the method can be inlined attributes = ((RAttributeStorage) arg).getAttributes(); } else { - profiledArg = argProfile.profile(arg); - attributes = profiledArg.getAttributes(); + arg = argProfile.profile(arg); + attributes = arg.getAttributes(); } if (noAttributesProfile.profile(attributes != null)) { if (access == null) { @@ -147,7 +146,7 @@ public abstract class ClassHierarchyNode extends UnaryNode { return classHierarchy; } } - return withImplicitTypes ? arg.getImplicitClass() : null; + return withImplicitTypes ? argProfile.profile(arg).getImplicitClass() : null; } protected static boolean isRTypedValue(Object obj) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/WrapDefaultArgumentNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/WrapDefaultArgumentNode.java index 0d9c02ebf5..bb3d87e04f 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/WrapDefaultArgumentNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/WrapDefaultArgumentNode.java @@ -49,7 +49,7 @@ public final class WrapDefaultArgumentNode extends WrapArgumentBaseNode { if (rShareable != null) { shareable.enter(); if (isShared.profile(rShareable.isShared())) { - return ((RShareable) result).copy(); + return rShareable.copy(); } else { ((RShareable) result).incRefCount(); } -- GitLab