Skip to content
Snippets Groups Projects
Commit af8edd15 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

add various profiles

parent d521a321
No related branches found
No related tags found
No related merge requests found
Showing with 31 additions and 17 deletions
......@@ -149,6 +149,7 @@ public abstract class Assign extends RBuiltinNode.Arg4 {
}
protected final ValueProfile frameAccessProfile = ValueProfile.createClassProfile();
protected final ValueProfile frameProfile = ValueProfile.createClassProfile();
public abstract void execute(VirtualFrame frame, REnvironment env, String name, Object value);
......@@ -156,11 +157,15 @@ public abstract class Assign extends RBuiltinNode.Arg4 {
return ResolvedWriteSuperFrameVariableNodeGen.create(name, Mode.REGULAR, null, null, FrameSlotNode.create(findOrAddFrameSlot(envDesc, name, FrameSlotKind.Illegal)));
}
@Specialization(guards = {"env.getFrame(frameAccessProfile).getFrameDescriptor() == envDesc", "write.getName().equals(name)"})
protected FrameDescriptor getFrameDescriptor(REnvironment env) {
return frameProfile.profile(env.getFrame(frameAccessProfile)).getFrameDescriptor();
}
@Specialization(guards = {"getFrameDescriptor(env) == envDesc", "write.getName().equals(name)"})
protected void assignCached(VirtualFrame frame, REnvironment env, @SuppressWarnings("unused") String name, Object value,
@Cached("env.getFrame().getFrameDescriptor()") @SuppressWarnings("unused") FrameDescriptor envDesc,
@Cached("createWrite(name, envDesc)") ResolvedWriteSuperFrameVariableNode write) {
write.execute(frame, value, env.getFrame(frameAccessProfile));
write.execute(frame, value, frameProfile.profile(env.getFrame(frameAccessProfile)));
}
@Specialization(replaces = "assignCached")
......
......@@ -127,6 +127,7 @@ public abstract class DoCall extends RBuiltinNode.Arg4 implements InternalRSynta
@Child private GetNamesAttributeNode getNamesNode;
@Child private SetVisibilityNode setVisibilityNode;
private final ValueProfile frameAccessProfile = ValueProfile.createClassProfile();
private final ValueProfile frameProfile = ValueProfile.createClassProfile();
private final RNodeClosureCache languagesClosureCache = new RNodeClosureCache();
private final SymbolClosureCache symbolsClosureCache = new SymbolClosureCache();
......@@ -137,7 +138,7 @@ public abstract class DoCall extends RBuiltinNode.Arg4 implements InternalRSynta
public abstract Object execute(VirtualFrame virtualFrame, String funcName, RFunction func, RList argsAsList, boolean quote, REnvironment env);
protected FrameDescriptor getFrameDescriptor(REnvironment env) {
return env.getFrame(frameAccessProfile).getFrameDescriptor();
return frameProfile.profile(env.getFrame(frameAccessProfile)).getFrameDescriptor();
}
/**
......@@ -152,7 +153,7 @@ public abstract class DoCall extends RBuiltinNode.Arg4 implements InternalRSynta
@Cached("create()") GetVisibilityNode getVisibilityNode,
@Cached("createBinaryProfile()") ConditionProfile quoteProfile,
@Cached("create()") BranchProfile containsRSymbolProfile) {
MaterializedFrame promiseFrame = env.getFrame(frameAccessProfile).materialize();
MaterializedFrame promiseFrame = frameProfile.profile(env.getFrame(frameAccessProfile)).materialize();
RArgsValuesAndNames args = getArguments(promiseFrame, quote, quoteProfile, containsRSymbolProfile, argsAsList);
RCaller caller = getExplicitCaller(virtualFrame, promiseFrame, funcName, func, args);
MaterializedFrame evalFrame = getEvalFrame(virtualFrame, promiseFrame);
......
......@@ -48,6 +48,7 @@ import com.oracle.truffle.r.runtime.builtins.RBuiltin;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RDataFactory.VectorFactory;
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
import com.oracle.truffle.r.runtime.env.frame.FrameSlotChangeMonitor;
import com.oracle.truffle.r.runtime.nodes.InternalRSyntaxNodeChildren;
......@@ -84,10 +85,11 @@ public abstract class Lapply extends RBuiltinNode.Arg2 {
@Specialization
protected Object lapply(VirtualFrame frame, RAbstractVector vec, RFunction fun,
@Cached("create()") ExtractNamesAttributeNode extractNamesNode) {
@Cached("create()") ExtractNamesAttributeNode extractNamesNode,
@Cached("create()") VectorFactory factory) {
Object[] result = lapply.execute(frame, vec, fun);
// set here else it gets overridden by the iterator evaluation
return RDataFactory.createList(result, extractNamesNode.execute(vec));
return factory.createList(result, extractNamesNode.execute(vec));
}
@Specialization
......
......@@ -41,6 +41,7 @@ import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RList;
import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.RStringVector;
import com.oracle.truffle.r.runtime.data.RDataFactory.VectorFactory;
@RBuiltin(name = "list", kind = PRIMITIVE, parameterNames = {"..."}, behavior = PURE)
public abstract class ListBuiltin extends RBuiltinNode.Arg1 {
......@@ -48,6 +49,7 @@ public abstract class ListBuiltin extends RBuiltinNode.Arg1 {
protected static final int CACHE_LIMIT = 2;
protected static final int MAX_SHARE_OBJECT_NODES = 16;
@Child private VectorFactory factory = VectorFactory.create();
@Children private final ShareObjectNode[] shareObjectNodes = new ShareObjectNode[MAX_SHARE_OBJECT_NODES];
private final ConditionProfile namesNull = ConditionProfile.createBinaryProfile();
......@@ -78,8 +80,7 @@ public abstract class ListBuiltin extends RBuiltinNode.Arg1 {
String orgName = signature.getName(i);
names[i] = (orgName == null ? RRuntime.NAMES_ATTR_EMPTY_VALUE : orgName);
}
RStringVector result = RDataFactory.createStringVector(names, RDataFactory.COMPLETE_VECTOR);
return result;
return factory.createStringVector(names, RDataFactory.COMPLETE_VECTOR);
}
/**
......@@ -99,7 +100,7 @@ public abstract class ListBuiltin extends RBuiltinNode.Arg1 {
for (int i = 0; i < cachedLength; i++) {
getShareObjectNode(i).execute(argArray[i]);
}
return RDataFactory.createList(argArray, cachedArgNames);
return factory.createList(argArray, cachedArgNames);
}
@Specialization(guards = "!args.isEmpty()")
......@@ -109,7 +110,7 @@ public abstract class ListBuiltin extends RBuiltinNode.Arg1 {
for (int i = 0; i < argArray.length; i++) {
shareObjectNode.execute(argArray[i]);
}
return RDataFactory.createList(argArray, argNameVector(args.getSignature()));
return factory.createList(argArray, argNameVector(args.getSignature()));
}
@Specialization(guards = "args.isEmpty()")
......@@ -119,7 +120,7 @@ public abstract class ListBuiltin extends RBuiltinNode.Arg1 {
@Specialization
protected RList listMissing(@SuppressWarnings("unused") RMissing missing) {
return RDataFactory.createList(new Object[]{});
return factory.createList(new Object[]{});
}
@Specialization(guards = {"!isRArgsValuesAndNames(value)", "!isRMissing(value)"})
......@@ -130,7 +131,7 @@ public abstract class ListBuiltin extends RBuiltinNode.Arg1 {
CompilerDirectives.transferToInterpreterAndInvalidate();
suppliedSignatureArgNames = argNameVector(ArgumentsSignature.empty(1));
}
return RDataFactory.createList(new Object[]{value}, suppliedSignatureArgNames);
return factory.createList(new Object[]{value}, suppliedSignatureArgNames);
}
private ShareObjectNode getShareObjectNode(int index) {
......
......@@ -72,6 +72,8 @@ public abstract class StandardGeneric extends RBuiltinNode.Arg2 {
private final BranchProfile noGenFunFound = BranchProfile.create();
private final ConditionProfile sameNamesProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile isBuiltinProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile isDeferredProfile = ConditionProfile.createBinaryProfile();
static {
Casts casts = new Casts(StandardGeneric.class);
......@@ -83,9 +85,9 @@ public abstract class StandardGeneric extends RBuiltinNode.Arg2 {
private Object stdGenericInternal(VirtualFrame frame, String fname, RFunction fdef) {
RFunction def = fdef;
if (def.isBuiltin()) {
if (isBuiltinProfile.profile(def.isBuiltin())) {
def = RContext.getInstance().getPrimitiveMethodsInfo().getPrimGeneric(def.getRBuiltin().getPrimMethodIndex());
if (def == null) {
if (isDeferredProfile.profile(def == null)) {
return RRuntime.DEFERRED_DEFAULT_MARKER;
}
}
......
......@@ -33,6 +33,7 @@ import com.oracle.truffle.r.runtime.env.REnvironment;
*/
public final class GetBaseEnvFrameNode extends Node {
private final ValueProfile frameAccessProfile = ValueProfile.createClassProfile();
private final ValueProfile frameProfile = ValueProfile.createClassProfile();
private final ValueProfile baseEnvProfile = ValueProfile.createIdentityProfile();
public static GetBaseEnvFrameNode create() {
......@@ -41,6 +42,6 @@ public final class GetBaseEnvFrameNode extends Node {
public MaterializedFrame execute() {
REnvironment baseEnv = baseEnvProfile.profile(REnvironment.baseEnv());
return baseEnv.getFrame(frameAccessProfile);
return frameProfile.profile(baseEnv.getFrame(frameAccessProfile));
}
}
......@@ -38,6 +38,7 @@ public abstract class DispatchGeneric extends RBaseNode {
public abstract Object executeObject(VirtualFrame frame, REnvironment mtable, RStringVector classes, RFunction fdef, String fname);
private final ConditionProfile singleStringProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile isDeferredProfile = ConditionProfile.createBinaryProfile();
private final BranchProfile equalsMethodRequired = BranchProfile.create();
@Child private LoadMethod loadMethod = LoadMethodNodeGen.create();
@Child private ExecuteMethod executeMethod = new ExecuteMethod();
......@@ -78,7 +79,7 @@ public abstract class DispatchGeneric extends RBaseNode {
RFunction currentFunction = ReadVariableNode.lookupFunction(".InheritForDispatch", methodsEnv.getFrame(), true, true);
method = (RFunction) RContext.getEngine().evalFunction(currentFunction, frame.materialize(), RCaller.create(frame, RASTUtils.getOriginalCall(this)), true, null, classes, fdef, mtable);
}
if (method.isBuiltin() || getInheritsInternalDispatchCheckNode().execute(method)) {
if (isDeferredProfile.profile(method.isBuiltin() || getInheritsInternalDispatchCheckNode().execute(method))) {
return RRuntime.DEFERRED_DEFAULT_MARKER;
}
method = loadMethod.executeRFunction(frame, method, fname);
......
......@@ -68,6 +68,7 @@ abstract class LoadMethod extends RBaseNode {
@Specialization
protected RFunction loadMethod(VirtualFrame frame, RFunction fdef, String fname,
@Cached("createClassProfile()") ValueProfile regFrameAccessProfile,
@Cached("createClassProfile()") ValueProfile regFrameProfile,
@Cached("createClassProfile()") ValueProfile methodsFrameAccessProfile) {
DynamicObject attributes = fdef.getAttributes();
assert fdef.isBuiltin() || attributes != null;
......@@ -115,7 +116,7 @@ abstract class LoadMethod extends RBaseNode {
RFunction ret;
if (fdef.getAttributes() != null && moreAttributes.profile(found < fdef.getAttributes().size())) {
RFunction currentFunction;
REnvironment methodsEnv = (REnvironment) methodsEnvRead.execute(frame, REnvironment.getNamespaceRegistry().getFrame(regFrameAccessProfile));
REnvironment methodsEnv = (REnvironment) methodsEnvRead.execute(frame, regFrameProfile.profile(REnvironment.getNamespaceRegistry().getFrame(regFrameAccessProfile)));
if (loadMethodFind == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
loadMethodFind = insert(ReadVariableNode.createFunctionLookup(RRuntime.R_LOAD_METHOD_NAME));
......
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