From 023fa976cd45feeb0cdefc3021c52c69704ecaec Mon Sep 17 00:00:00 2001 From: Zbynek Slajchrt <zbynek.slajchrt@oracle.com> Date: Tue, 6 Dec 2016 19:19:26 +0100 Subject: [PATCH] several inlining issues fixed --- .../truffle/r/nodes/builtin/base/Bind.java | 8 +++-- .../r/nodes/attributes/GetAttributeNode.java | 16 ++++++++-- .../attributes/GetFixedAttributeNode.java | 16 ++++++++-- .../attributes/HasFixedAttributeNode.java | 16 ++++++++-- .../SpecialAttributesFunctions.java | 31 ++++++++++++++----- 5 files changed, 70 insertions(+), 17 deletions(-) diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Bind.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Bind.java index 7532f080c1..28a3e5cd64 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Bind.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Bind.java @@ -387,9 +387,10 @@ public abstract class Bind extends RBaseNode { } protected int[] getDimensions(RAbstractVector vector) { - int[] dimensions = getVectorDimensions(vector); + RAbstractVector vectorProfiled = vectorProfile.profile(vector); + int[] dimensions = getVectorDimensions(vectorProfiled); if (dimensions == null || dimensions.length != 2) { - return type == BindType.cbind ? new int[]{vector.getLength(), 1} : new int[]{1, vector.getLength()}; + return type == BindType.cbind ? new int[]{vectorProfiled.getLength(), 1} : new int[]{1, vectorProfiled.getLength()}; } else { assert dimensions.length == 2; return dimensions; @@ -493,7 +494,8 @@ public abstract class Bind extends RBaseNode { int[] resultDimensions = new int[2]; int[] secondDims = new int[vectors.length]; boolean notEqualRows = getResultDimensions(vectors, resultDimensions, secondDims); - RVector<?> result = resultProfile.profile(vectors[0].createEmptySameType(resultDimensions[0] * resultDimensions[1], complete)); + RAbstractVector first = vectorProfile.profile(vectors[0]); + RVector<?> result = resultProfile.profile(first.createEmptySameType(resultDimensions[0] * resultDimensions[1], complete)); int ind = 0; Object rowDimResultNames = RNull.instance; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/GetAttributeNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/GetAttributeNode.java index 27d4fd9012..858530667f 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/GetAttributeNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/GetAttributeNode.java @@ -30,7 +30,10 @@ import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.Location; import com.oracle.truffle.api.object.Shape; import com.oracle.truffle.api.profiles.BranchProfile; +import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.api.profiles.ValueProfile; import com.oracle.truffle.r.runtime.data.RAttributable; +import com.oracle.truffle.r.runtime.data.RAttributeStorage; /** * This node is responsible for retrieving a value from an arbitrary attribute. It accepts both @@ -70,8 +73,17 @@ public abstract class GetAttributeNode extends AttributeAccessNode { @Specialization protected Object getAttrFromAttributable(RAttributable x, String name, - @Cached("create()") BranchProfile attrNullProfile) { - DynamicObject attributes = x.getAttributes(); + @Cached("create()") BranchProfile attrNullProfile, + @Cached("createBinaryProfile()") ConditionProfile attrStorageProfile, + @Cached("createClassProfile()") ValueProfile xTypeProfile) { + + DynamicObject attributes; + if (attrStorageProfile.profile(x instanceof RAttributeStorage)) { + attributes = ((RAttributeStorage) x).getAttributes(); + } else { + attributes = xTypeProfile.profile(x).getAttributes(); + } + if (attributes == null) { attrNullProfile.enter(); return null; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/GetFixedAttributeNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/GetFixedAttributeNode.java index f4e6a5bd94..4fd0e9cba0 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/GetFixedAttributeNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/GetFixedAttributeNode.java @@ -30,9 +30,12 @@ import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.Location; import com.oracle.truffle.api.object.Shape; import com.oracle.truffle.api.profiles.BranchProfile; +import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.api.profiles.ValueProfile; import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.GetDimAttributeNode; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.data.RAttributable; +import com.oracle.truffle.r.runtime.data.RAttributeStorage; /** * This node is responsible for retrieving a value from the predefined (fixed) attribute. It accepts @@ -88,8 +91,17 @@ public abstract class GetFixedAttributeNode extends FixedAttributeAccessNode { @Specialization protected Object getAttrFromAttributable(RAttributable x, - @Cached("create()") BranchProfile attrNullProfile) { - DynamicObject attributes = x.getAttributes(); + @Cached("create()") BranchProfile attrNullProfile, + @Cached("createBinaryProfile()") ConditionProfile attrStorageProfile, + @Cached("createClassProfile()") ValueProfile xTypeProfile) { + + DynamicObject attributes; + if (attrStorageProfile.profile(x instanceof RAttributeStorage)) { + attributes = ((RAttributeStorage) x).getAttributes(); + } else { + attributes = xTypeProfile.profile(x).getAttributes(); + } + if (attributes == null) { attrNullProfile.enter(); return null; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/HasFixedAttributeNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/HasFixedAttributeNode.java index fa44bfdcc6..46ee95ea5b 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/HasFixedAttributeNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/HasFixedAttributeNode.java @@ -30,9 +30,12 @@ import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.Location; import com.oracle.truffle.api.object.Shape; import com.oracle.truffle.api.profiles.BranchProfile; +import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.api.profiles.ValueProfile; import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.GetDimAttributeNode; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.data.RAttributable; +import com.oracle.truffle.r.runtime.data.RAttributeStorage; /** * This node is responsible for determining the existence of the predefined (fixed) attribute. It @@ -80,8 +83,17 @@ public abstract class HasFixedAttributeNode extends FixedAttributeAccessNode { @Specialization protected boolean hasAttrFromAttributable(RAttributable x, - @Cached("create()") BranchProfile attrNullProfile) { - DynamicObject attributes = x.getAttributes(); + @Cached("create()") BranchProfile attrNullProfile, + @Cached("createBinaryProfile()") ConditionProfile attrStorageProfile, + @Cached("createClassProfile()") ValueProfile xTypeProfile) { + + DynamicObject attributes; + if (attrStorageProfile.profile(x instanceof RAttributeStorage)) { + attributes = ((RAttributeStorage) x).getAttributes(); + } else { + attributes = xTypeProfile.profile(x).getAttributes(); + } + if (attributes == null) { attrNullProfile.enter(); return false; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java index 1670540a79..241be5a0e6 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SpecialAttributesFunctions.java @@ -202,7 +202,8 @@ public final class SpecialAttributesFunctions { } @Specialization - protected void setNamesInContainer(RAbstractContainer x, RStringVector names, @Cached("createClassProfile()") ValueProfile contClassProfile) { + protected void setNamesInContainer(RAbstractContainer x, RStringVector names, + @Cached("createClassProfile()") ValueProfile contClassProfile) { RAbstractContainer xProfiled = contClassProfile.profile(x); xProfiled.setNames(names); } @@ -215,16 +216,30 @@ public final class SpecialAttributesFunctions { } @Specialization - protected void setOneDimInContainer(RAbstractContainer x, Integer dim, @Cached("createClassProfile()") ValueProfile contClassProfile) { - RAbstractContainer xProfiled = contClassProfile.profile(x); - // xProfiled.setDimensions(new int[]{dim}); - xProfiled.setAttr(RRuntime.DIM_ATTR_KEY, new int[]{dim}); + protected void setOneDimInContainer(RAbstractContainer x, Integer dim, + @Cached("createClassProfile()") ValueProfile contClassProfile, + @Cached("createBinaryProfile()") ConditionProfile vectorProfile) { + int[] dims = new int[]{dim}; + if (vectorProfile.profile(x instanceof RVector)) { + ((RVector<?>) x).setDimensions(dims); + } else { + RAbstractContainer xProfiled = contClassProfile.profile(x); + xProfiled.setDimensions(dims); + } + } @Specialization - protected void setDimsInContainer(RAbstractContainer x, RAbstractIntVector dims, @Cached("createClassProfile()") ValueProfile contClassProfile) { - RAbstractContainer xProfiled = contClassProfile.profile(x); - xProfiled.setDimensions(dims.materialize().getDataCopy()); + protected void setDimsInContainer(RAbstractContainer x, RAbstractIntVector dims, + @Cached("createClassProfile()") ValueProfile contClassProfile, + @Cached("createBinaryProfile()") ConditionProfile vectorProfile) { + int[] dimsArr = dims.materialize().getDataCopy(); + if (vectorProfile.profile(x instanceof RVector)) { + ((RVector<?>) x).setDimensions(dimsArr); + } else { + RAbstractContainer xProfiled = contClassProfile.profile(x); + xProfiled.setDimensions(dimsArr); + } } } -- GitLab