From 145e7b91896907cb41a171b1934a30065701ecae Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Wed, 12 Apr 2017 13:23:24 +0200 Subject: [PATCH] more node copying in replacements and specials --- .../r/nodes/control/ReplacementNode.java | 9 ++++-- .../r/nodes/function/RCallSpecialNode.java | 29 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java index 13c607e358..2eb77334c9 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java @@ -60,6 +60,11 @@ abstract class ReplacementNode extends OperatorNode { this.lhs = lhs; } + @Override + public final Node deepCopy() { + return RContext.getASTBuilder().process(this).asRNode(); + } + public static ReplacementNode create(SourceSection source, RSyntaxLookup operator, RNode target, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, String targetVarName, boolean isSuper, int tempNamesStartIndex, boolean isVoid) { CompilerAsserts.neverPartOfCompilation(); @@ -145,7 +150,7 @@ abstract class ReplacementNode extends OperatorNode { RSyntaxNode[] newArgs = new RSyntaxNode[2]; newArgs[0] = (RSyntaxNode) oldArgs[0]; newArgs[1] = builder.lookup(oldArgs[1].getLazySourceSection(), ((RSyntaxLookup) oldArgs[1]).getIdentifier() + "<-", true); - newSyntaxLHS = RCallSpecialNode.createCall(callLHS.getLazySourceSection(), ((RSyntaxNode) callLHS.getSyntaxLHS()).asRNode(), callLHS.getSyntaxSignature(), newArgs); + newSyntaxLHS = RCallSpecialNode.createCall(callLHS.getLazySourceSection(), builder.process(callLHS.getSyntaxLHS(), codeBuilderContext).asRNode(), callLHS.getSyntaxSignature(), newArgs); } return RCallSpecialNode.createCallInReplace(source, newSyntaxLHS.asRNode(), ArgumentsSignature.get(names), argNodes, 0, argNodes.length - 1).asRNode(); } @@ -346,7 +351,7 @@ abstract class ReplacementNode extends OperatorNode { GenericReplacementNode(SourceSection source, RSyntaxLookup operator, RNode target, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, String targetVarName, boolean isSuper, int tempNamesStartIndex) { - super(source, operator, lhs, rhs, tempNamesStartIndex); + super(source, operator, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), tempNamesStartIndex); /* * When there are more than two function calls in LHS, then we save some function calls * by saving the intermediate results into temporary variables and reusing them. diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallSpecialNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallSpecialNode.java index 5ba452ebe4..e87a36945f 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallSpecialNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallSpecialNode.java @@ -24,7 +24,9 @@ package com.oracle.truffle.r.nodes.function; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeCost; import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.profiles.ConditionProfile; @@ -165,7 +167,11 @@ public final class RCallSpecialNode extends RCallBaseNode implements RSyntaxNode */ private RCallSpecialNode callSpecialParent; - private RCallSpecialNode(SourceSection sourceSection, RNode functionNode, RFunction expectedFunction, RSyntaxNode[] arguments, ArgumentsSignature signature, RNode special) { + private final boolean inReplace; + private final int[] ignoredArguments; + + private RCallSpecialNode(SourceSection sourceSection, RNode functionNode, RFunction expectedFunction, RSyntaxNode[] arguments, ArgumentsSignature signature, RNode special, boolean inReplace, + int[] ignoredArguments) { this.sourceSection = sourceSection; this.expectedFunction = expectedFunction; this.special = special; @@ -173,6 +179,8 @@ public final class RCallSpecialNode extends RCallBaseNode implements RSyntaxNode this.arguments = arguments; this.signature = signature; this.visible = expectedFunction.getRBuiltin().getVisibility(); + this.inReplace = inReplace; + this.ignoredArguments = ignoredArguments; } /** @@ -264,7 +272,7 @@ public final class RCallSpecialNode extends RCallBaseNode implements RSyntaxNode RFunction expectedFunction = RContext.lookupBuiltin(name); RInternalError.guarantee(expectedFunction != null); - RCallSpecialNode callSpecial = new RCallSpecialNode(sourceSection, functionNode, expectedFunction, arguments, signature, special); + RCallSpecialNode callSpecial = new RCallSpecialNode(sourceSection, functionNode, expectedFunction, arguments, signature, special, inReplace, ignoredArguments); for (int i = 0; i < arguments.length; i++) { if (!inReplace || !contains(ignoredArguments, i)) { if (arguments[i] instanceof RCallSpecialNode) { @@ -316,6 +324,23 @@ public final class RCallSpecialNode extends RCallBaseNode implements RSyntaxNode } } + @TruffleBoundary + private static void log(String format, Object... args) { + System.out.println(String.format(format, args)); + } + + @Override + public Node deepCopy() { + assert !inReplace && callSpecialParent == null && ignoredArguments.length == 0; + RCallSpecialNode node = (RCallSpecialNode) RContext.getASTBuilder().process(this).asRNode(); + node.functionNode = node.insert(node.functionNode); + node.special = node.insert(node.special); + if (node.visibility != null) { + node.visibility = insert(node.visibility); + } + return node; + } + private RCallNode getRCallNode(RSyntaxNode[] newArguments) { return RCallNode.createCall(sourceSection, functionNode, signature, newArguments); } -- GitLab