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

use fast path for match.arg (instead of substitution)

parent f4eff2b9
No related branches found
No related tags found
No related merge requests found
...@@ -134,6 +134,8 @@ import com.oracle.truffle.r.nodes.builtin.fastr.FastRStackTrace; ...@@ -134,6 +134,8 @@ import com.oracle.truffle.r.nodes.builtin.fastr.FastRStackTrace;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRStackTraceNodeGen; import com.oracle.truffle.r.nodes.builtin.fastr.FastRStackTraceNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRSyntaxTree; import com.oracle.truffle.r.nodes.builtin.fastr.FastRSyntaxTree;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRSyntaxTreeNodeGen; import com.oracle.truffle.r.nodes.builtin.fastr.FastRSyntaxTreeNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRTestsTry;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRTestsTryNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRThrowIt; import com.oracle.truffle.r.nodes.builtin.fastr.FastRThrowIt;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRThrowItNodeGen; import com.oracle.truffle.r.nodes.builtin.fastr.FastRThrowItNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRTrace; import com.oracle.truffle.r.nodes.builtin.fastr.FastRTrace;
...@@ -142,8 +144,6 @@ import com.oracle.truffle.r.nodes.builtin.fastr.FastRTree; ...@@ -142,8 +144,6 @@ import com.oracle.truffle.r.nodes.builtin.fastr.FastRTree;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRTreeNodeGen; import com.oracle.truffle.r.nodes.builtin.fastr.FastRTreeNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRTreeStats; import com.oracle.truffle.r.nodes.builtin.fastr.FastRTreeStats;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRTreeStatsNodeGen; import com.oracle.truffle.r.nodes.builtin.fastr.FastRTreeStatsNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRTestsTry;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRTestsTryNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastrDqrls; import com.oracle.truffle.r.nodes.builtin.fastr.FastrDqrls;
import com.oracle.truffle.r.nodes.builtin.fastr.FastrDqrlsNodeGen; import com.oracle.truffle.r.nodes.builtin.fastr.FastrDqrlsNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.memprof.FastRprofmem; import com.oracle.truffle.r.nodes.builtin.fastr.memprof.FastRprofmem;
...@@ -638,7 +638,6 @@ public class BasePackage extends RBuiltinPackage { ...@@ -638,7 +638,6 @@ public class BasePackage extends RBuiltinPackage {
add(MatMult.class, MatMult::create); add(MatMult.class, MatMult::create);
add(Match.class, MatchNodeGen::create); add(Match.class, MatchNodeGen::create);
add(MatchFun.class, MatchFunNodeGen::create); add(MatchFun.class, MatchFunNodeGen::create);
add(MatchArg.class, MatchArgNodeGen::create);
add(Matrix.class, MatrixNodeGen::create); add(Matrix.class, MatrixNodeGen::create);
add(Max.class, MaxNodeGen::create); add(Max.class, MaxNodeGen::create);
add(Mean.class, MeanNodeGen::create); add(Mean.class, MeanNodeGen::create);
...@@ -876,6 +875,7 @@ public class BasePackage extends RBuiltinPackage { ...@@ -876,6 +875,7 @@ public class BasePackage extends RBuiltinPackage {
addFastPath(baseFrame, "rbind", FastPathFactory.FORCED_EAGER_ARGS); addFastPath(baseFrame, "rbind", FastPathFactory.FORCED_EAGER_ARGS);
addFastPath(baseFrame, "seq.default", SeqFunctionsFactory.SeqDefaultFastPathNodeGen::create, RVisibility.ON); addFastPath(baseFrame, "seq.default", SeqFunctionsFactory.SeqDefaultFastPathNodeGen::create, RVisibility.ON);
addFastPath(baseFrame, "seq", SeqFunctionsFactory.SeqFastPathNodeGen::create, RVisibility.ON); addFastPath(baseFrame, "seq", SeqFunctionsFactory.SeqFastPathNodeGen::create, RVisibility.ON);
addFastPath(baseFrame, "match.arg", MatchArgFastPathNodeGen::create, MatchArgFastPath.class);
setContainsDispatch(baseFrame, "eval", "[.data.frame", "[[.data.frame", "[<-.data.frame", "[[<-.data.frame"); setContainsDispatch(baseFrame, "eval", "[.data.frame", "[[.data.frame", "[<-.data.frame", "[[<-.data.frame");
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
package com.oracle.truffle.r.nodes.builtin.base; package com.oracle.truffle.r.nodes.builtin.base;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean;
import static com.oracle.truffle.r.nodes.builtin.casts.fluent.CastNodeBuilder.newCastBuilder; import static com.oracle.truffle.r.nodes.builtin.casts.fluent.CastNodeBuilder.newCastBuilder;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX;
...@@ -39,9 +40,7 @@ import com.oracle.truffle.api.frame.VirtualFrame; ...@@ -39,9 +40,7 @@ import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.r.nodes.RRootNode; import com.oracle.truffle.r.nodes.RRootNode;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue; import com.oracle.truffle.r.nodes.builtin.base.MatchArgFastPathNodeGen.MatchArgInternalNodeGen;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.nodes.builtin.base.MatchArgNodeGen.MatchArgInternalNodeGen;
import com.oracle.truffle.r.nodes.function.FormalArguments; import com.oracle.truffle.r.nodes.function.FormalArguments;
import com.oracle.truffle.r.nodes.function.PromiseHelperNode; import com.oracle.truffle.r.nodes.function.PromiseHelperNode;
import com.oracle.truffle.r.nodes.unary.CastNode; import com.oracle.truffle.r.nodes.unary.CastNode;
...@@ -59,20 +58,12 @@ import com.oracle.truffle.r.runtime.data.RNull; ...@@ -59,20 +58,12 @@ import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.RPromise; import com.oracle.truffle.r.runtime.data.RPromise;
import com.oracle.truffle.r.runtime.data.RTypes; import com.oracle.truffle.r.runtime.data.RTypes;
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
import com.oracle.truffle.r.runtime.nodes.RFastPathNode;
import com.oracle.truffle.r.runtime.nodes.RNode; import com.oracle.truffle.r.runtime.nodes.RNode;
import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
@RBuiltin(name = "match.arg", kind = SUBSTITUTE, parameterNames = {"arg", "choices", "several.ok"}, nonEvalArgs = {0}, behavior = COMPLEX) @RBuiltin(name = "match.arg", kind = SUBSTITUTE, parameterNames = {"arg", "choices", "several.ok"}, nonEvalArgs = {0}, behavior = COMPLEX)
public abstract class MatchArg extends RBuiltinNode.Arg3 { public abstract class MatchArgFastPath extends RFastPathNode {
static {
Casts.noCasts(MatchArg.class);
}
@Override
public Object[] getDefaultParameterValues() {
return new Object[]{RMissing.instance, RMissing.instance, RRuntime.LOGICAL_FALSE};
}
@TypeSystemReference(RTypes.class) @TypeSystemReference(RTypes.class)
protected abstract static class MatchArgInternal extends Node { protected abstract static class MatchArgInternal extends Node {
...@@ -225,7 +216,7 @@ public abstract class MatchArg extends RBuiltinNode.Arg3 { ...@@ -225,7 +216,7 @@ public abstract class MatchArg extends RBuiltinNode.Arg3 {
@Specialization(limit = "1", guards = "cache.choicesValue.isSupported(frame, arg)") @Specialization(limit = "1", guards = "cache.choicesValue.isSupported(frame, arg)")
protected Object matchArg(VirtualFrame frame, RPromise arg, @SuppressWarnings("unused") RMissing choices, Object severalOK, protected Object matchArg(VirtualFrame frame, RPromise arg, @SuppressWarnings("unused") RMissing choices, Object severalOK,
@Cached("new(frame, arg)") MatchArgNode cache) { @Cached("new(frame, arg)") MatchArgNode cache) {
return cache.internal.castAndExecute(cache.promiseHelper.evaluate(frame, arg), cache.choicesValue.execute(frame), severalOK); return cache.internal.castAndExecute(cache.promiseHelper.evaluate(frame, arg), cache.choicesValue.execute(frame), severalOK == RMissing.instance ? RRuntime.LOGICAL_FALSE : severalOK);
} }
public static final class MatchArgNode extends Node { public static final class MatchArgNode extends Node {
...@@ -248,7 +239,7 @@ public abstract class MatchArg extends RBuiltinNode.Arg3 { ...@@ -248,7 +239,7 @@ public abstract class MatchArg extends RBuiltinNode.Arg3 {
protected Object matchArg(VirtualFrame frame, RPromise arg, Object choices, Object severalOK, protected Object matchArg(VirtualFrame frame, RPromise arg, Object choices, Object severalOK,
@Cached("createInternal()") MatchArgInternal internal, @Cached("createInternal()") MatchArgInternal internal,
@Cached("new()") PromiseHelperNode promiseHelper) { @Cached("new()") PromiseHelperNode promiseHelper) {
return internal.castAndExecute(promiseHelper.evaluate(frame, arg), choices, severalOK); return internal.castAndExecute(promiseHelper.evaluate(frame, arg), choices, severalOK == RMissing.instance ? RRuntime.LOGICAL_FALSE : severalOK);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
......
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