Skip to content
Snippets Groups Projects
Commit 88c28fc9 authored by Zbynek Slajchrt's avatar Zbynek Slajchrt
Browse files

A couple of fix-ups in attribute related nodes

parent 116c016f
No related branches found
No related tags found
No related merge requests found
......@@ -29,12 +29,17 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.r.nodes.attributes.SetFixedAttributeNode;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.r.nodes.attributes.InitAttributesNode;
import com.oracle.truffle.r.nodes.attributes.SetFixedAttributeNode;
import com.oracle.truffle.r.nodes.builtin.CastBuilder;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.nodes.function.opt.ReuseNonSharedNode;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
import com.oracle.truffle.r.runtime.data.RAttributeStorage;
import com.oracle.truffle.r.runtime.data.RAttributesLayout;
import com.oracle.truffle.r.runtime.data.RIntVector;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.RVector;
......@@ -61,8 +66,8 @@ public abstract class UpdateDim extends RBuiltinNode {
@Specialization
protected RAbstractVector updateDim(RAbstractVector vector, RAbstractIntVector dimensions,
@Cached("createDim()") SetFixedAttributeNode putDimensions,
@Cached("create()") InitAttributesNode initAttributes) {
@Cached("createBinaryProfile()") ConditionProfile initAttrProfile,
@Cached("createDim()") SetFixedAttributeNode putDimensions) {
RIntVector dimensionsMaterialized = dimensions.materialize();
int[] dimsData = dimensionsMaterialized.getDataCopy();
RVector.verifyDimensions(vector.getLength(), dimsData, this);
......@@ -70,7 +75,14 @@ public abstract class UpdateDim extends RBuiltinNode {
result.setInternalDimensions(dimsData);
result.setInternalNames(null);
result.setInternalDimNames(null);
putDimensions.execute(initAttributes.execute(result), dimensionsMaterialized);
DynamicObject attrs = result.getAttributes();
if (initAttrProfile.profile(attrs == null)) {
attrs = RAttributesLayout.createDim(dimensionsMaterialized);
result.initAttributes(attrs);
} else {
putDimensions.execute(attrs, dimensionsMaterialized);
}
return result;
}
}
......@@ -433,7 +433,6 @@ final class CachedExtractVectorNode extends CachedVectorNode {
protected abstract static class SetNamesNode extends Node {
@Child private SetFixedAttributeNode namesAttrSetter = SetFixedAttributeNode.createNames();
@Child private GetFixedAttributeNode namesAttrGetter = GetFixedAttributeNode.createNames();
public abstract void execute(RVector<?> container, Object newNames);
......@@ -446,7 +445,6 @@ final class CachedExtractVectorNode extends CachedVectorNode {
if (container.getAttributes() == null) {
// usual case
container.initAttributes(RAttributesLayout.createNames(newNames1));
namesAttrSetter.execute(container.initAttributes(), newNames1);
container.setInternalNames(newNames1);
} else {
// from an RLanguage extraction that set a name
......
......@@ -28,6 +28,7 @@ import com.oracle.truffle.api.dsl.Specialization;
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.ConditionProfile;
public abstract class GetAttributeNode extends AttributeAccessNode {
......@@ -41,14 +42,15 @@ public abstract class GetAttributeNode extends AttributeAccessNode {
public abstract Object execute(DynamicObject attrs, String name);
@Specialization(limit = "3", //
guards = {"location != null", "cachedName.equals(name)", "shapeCheck(shape, attrs)"}, //
guards = {"cachedName.equals(name)", "shapeCheck(shape, attrs)"}, //
assumptions = {"shape.getValidAssumption()"})
@SuppressWarnings("unused")
protected Object getAttrCached(DynamicObject attrs, String name,
@Cached("name") String cachedName,
@Cached("lookupShape(attrs)") Shape shape,
@Cached("lookupLocation(shape, name)") Location location) {
return location.get(attrs);
@Cached("lookupLocation(shape, name)") Location location,
@Cached("createBinaryProfile()") ConditionProfile nullProfile) {
return nullProfile.profile(location == null) ? null : location.get(attrs);
}
@TruffleBoundary
......
......@@ -28,6 +28,7 @@ import com.oracle.truffle.api.dsl.Specialization;
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.ConditionProfile;
import com.oracle.truffle.r.runtime.RRuntime;
public abstract class GetFixedAttributeNode extends FixedAttributeAccessNode {
......@@ -54,14 +55,19 @@ public abstract class GetFixedAttributeNode extends FixedAttributeAccessNode {
public abstract Object execute(DynamicObject attrs);
protected boolean hasProperty(Shape shape) {
return shape.hasProperty(name);
}
@Specialization(limit = "3", //
guards = {"shapeCheck(shape, attrs)", "location != null"}, //
guards = {"shapeCheck(shape, attrs)"}, //
assumptions = {"shape.getValidAssumption()"})
@SuppressWarnings("unused")
protected Object getAttrCached(DynamicObject attrs,
@Cached("lookupShape(attrs)") Shape shape,
@Cached("lookupLocation(shape, name)") Location location) {
return location.get(attrs);
@Cached("lookupLocation(shape, name)") Location location,
@Cached("createBinaryProfile()") ConditionProfile nullProfile) {
return nullProfile.profile(location == null) ? null : location.get(attrs);
}
@Specialization(contains = "getAttrCached")
......
......@@ -28,6 +28,7 @@ import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.Property;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.r.runtime.RRuntime;
public abstract class RemoveFixedAttributeNode extends FixedAttributeAccessNode {
......@@ -59,13 +60,17 @@ public abstract class RemoveFixedAttributeNode extends FixedAttributeAccessNode
public abstract void execute(DynamicObject attrs);
@Specialization(limit = "3", //
guards = {"shapeCheck(shape, attrs)", "property != null"}, //
guards = {"shapeCheck(shape, attrs)"}, //
assumptions = {"shape.getValidAssumption()"})
protected void removeAttrCached(DynamicObject attrs,
@Cached("lookupShape(attrs)") Shape shape,
@Cached("lookupProperty(shape, name)") Property property) {
Shape newShape = attrs.getShape().removeProperty(property);
attrs.setShapeAndResize(shape, newShape);
@Cached("lookupProperty(shape, name)") Property property,
@Cached("create()") BranchProfile notNullProfile) {
if (property != null) {
notNullProfile.enter();
Shape newShape = attrs.getShape().removeProperty(property);
attrs.setShapeAndResize(shape, newShape);
}
}
@Specialization(contains = "removeAttrCached")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment