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 7532f080c19d0b86026bed5a456fa030199eae76..28a3e5cd648b4679148037ac0d0fae5e82059078 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 27d4fd901217877176dd1fd89f3a62aeed794b5e..858530667ff7dc7246205f084dd710e3e0b2d631 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 f4e6a5bd94306f9f3ebda9a665631a5a737c25cb..4fd0e9cba05925452c34a0f4fdabb55c1502ac75 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 fa44bfdcc6bb57d5fe39759889ac9fce390411f4..46ee95ea5bc07b17cadc43b3939c0c86cbbd2094 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 1670540a7913dd1d94d54460cd34cc30230631cf..241be5a0e6f5b3514285efe7990f335b677a99a2 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); + } } }