Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding supernodes #185

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f7fbb14
Add specialized n-ary send nodes that send to an argument
smarr Nov 21, 2021
741fc3c
Implement IntIncrementNode and needed field access/storage support
smarr Jan 21, 2022
9377f1d
Generalize the IncOperationNode to arbitary values
smarr Jan 22, 2022
51e9a6a
Rename field to more consistent and explicit incValue
smarr Jan 22, 2022
9a2483c
Added LocalVariableIncNode and NonLocalVariableIncNode
smarr Jan 22, 2022
9931e1a
Add AssignLocalSquareToLocalNode
OctaveLarose Jan 23, 2022
6526cc6
Added initial tests, the todo list
smarr Jan 23, 2022
89377b2
Added [Non]LocalVariableSquareNode
smarr Jan 23, 2022
e72ba5b
Add [Non]LocalVariableReadSquareWriteNode
smarr Jan 23, 2022
bd3d369
Add StringEqualsNode, which is used for `expr = 'str'`, i.e. literal …
smarr Jan 23, 2022
107c989
Add [Non]LocalFieldStringEqualsNode
smarr Jan 23, 2022
57b868f
Adapt to use createGenericBinary
smarr Jan 24, 2022
e9a6922
Move all supernodes to same package
smarr Jan 24, 2022
348f90a
Restructure the Increment super nodes to support field increment with…
smarr Jan 25, 2022
e004bea
Add fallback code for UninitIncFieldNode, SomSom needs it...
smarr Jan 26, 2022
19bb759
Rename increment nodes for variables that use an int constant
smarr Jan 26, 2022
f15d40b
Add Inc[Non]LocalVariableNode
smarr Jan 26, 2022
87d590c
Fix test regression after Invokable changes being merged in
smarr Feb 15, 2022
8192c97
Adapt to use of frame slot index instead of FrameSlot
smarr Feb 22, 2022
d95dde2
Merge PR #144: Update Truffle and MX, and rename bd package to bdt
smarr Apr 25, 2022
9215df5
Add super node for `local := local foo`
smarr Feb 23, 2022
00f29ba
Add supernode for `isNil ifTrue:` sequence
smarr Feb 23, 2022
a55017a
Add LocalArgGreaterThanInt
smarr Jan 25, 2022
e532691
Add GreaterThanIntNode, LessThanIntNode, and LocalArgLessThanInt
smarr Jan 25, 2022
92f450f
Remove unsafe getFieldOffset use and suppress deprecation warning for…
smarr Apr 21, 2023
72626a1
Adapt to changes in send nodes
smarr Apr 23, 2023
3223c68
Fix merge issues in IntIncrementNode
smarr Apr 23, 2023
a7d9b2f
Fix based on changes in send nodes
smarr Apr 23, 2023
2186057
Things changed around the increment nodes
smarr Apr 23, 2023
450fcf7
Bump Java version in Eclipse project to Java 19
smarr Apr 23, 2023
d96d677
Fix class not moved in merge, deleted now
smarr Apr 23, 2023
853f0c9
The read+write square nodes may access locals in different lexical co…
smarr Apr 11, 2023
c10025b
Initialize separte test context for each test class
smarr Apr 24, 2023
87ca852
Remove redundant transferToInterpreterAndInvalidate()
smarr Apr 24, 2023
fecb6b1
Whitespace
smarr Apr 24, 2023
5d3dbf6
Keep child nodes only in AST interpreter
smarr Apr 24, 2023
4e2df51
Use instanceof pattern matching, and other code simplifications
smarr Apr 24, 2023
274c0e6
Added more tests for the string literal equality supernode
smarr Apr 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.targetPlatform=19
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.compliance=19
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand All @@ -24,7 +24,7 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.compiler.source=19
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=1
org.eclipse.jdt.core.formatter.align_type_members_on_columns=true
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
Expand Down
9 changes: 9 additions & 0 deletions src/bdt/inlining/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.oracle.truffle.api.nodes.Node;

import trufflesom.compiler.Variable.Local;


/**
* A {@link Variable} represents a variable most often in the user code, or sometimes internal
Expand Down Expand Up @@ -37,6 +39,13 @@ public interface Variable<N extends Node> {
*/
N getReadNode(int contextLevel, long coord);

N getIncNode(int contextLevel, long incValue, long coord);

N getSquareNode(int contextLevel, long coord);

N getReadSquareWriteNode(int writeContextLevel, long coord, Local readLocal,
int readContextLevel);

/**
* Create a node to write to this variable.
*
Expand Down
81 changes: 77 additions & 4 deletions src/trufflesom/compiler/MethodGenerationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@
import trufflesom.interpreter.nodes.ExpressionNode;
import trufflesom.interpreter.nodes.FieldNode;
import trufflesom.interpreter.nodes.FieldNode.FieldReadNode;
import trufflesom.interpreter.nodes.FieldNode.UninitFieldIncNode;
import trufflesom.interpreter.nodes.FieldNodeFactory.FieldWriteNodeGen;
import trufflesom.interpreter.nodes.LocalVariableNode.LocalVariableReadNode;
import trufflesom.interpreter.nodes.NonLocalVariableNode.NonLocalVariableReadNode;
import trufflesom.interpreter.nodes.ReturnNonLocalNode;
import trufflesom.interpreter.nodes.ReturnNonLocalNode.CatchNonLocalReturnNode;
import trufflesom.interpreter.nodes.UninitializedMessageSendNode;
import trufflesom.interpreter.nodes.literals.BlockNode;
import trufflesom.interpreter.nodes.specialized.IntIncrementNode;
import trufflesom.interpreter.supernodes.IntIncrementNode;
import trufflesom.interpreter.supernodes.LocalVarReadUnaryMsgWriteNode;
import trufflesom.interpreter.supernodes.LocalVariableSquareNode;
import trufflesom.interpreter.supernodes.NonLocalVarReadUnaryMsgWriteNode;
import trufflesom.interpreter.supernodes.NonLocalVariableSquareNode;
import trufflesom.interpreter.supernodes.UninitIncFieldNode;
import trufflesom.primitives.Primitives;
import trufflesom.primitives.arithmetic.AdditionPrim;
import trufflesom.vm.NotYetImplementedException;
import trufflesom.vmobjects.SClass;
import trufflesom.vmobjects.SInvokable;
import trufflesom.vmobjects.SInvokable.SMethod;
Expand Down Expand Up @@ -401,7 +410,56 @@ public ExpressionNode getLocalReadNode(final Variable variable, final long coord

public ExpressionNode getLocalWriteNode(final Variable variable,
final ExpressionNode valExpr, final long coord) {
return variable.getWriteNode(getContextLevel(variable), valExpr, coord);
int ctxLevel = getContextLevel(variable);

if (valExpr instanceof IntIncrementNode
&& ((IntIncrementNode) valExpr).doesAccessVariable(variable)) {
return ((IntIncrementNode) valExpr).createIncNode((Local) variable, ctxLevel);
}

if (ctxLevel == 0) {
if (valExpr instanceof LocalVariableSquareNode l) {
return variable.getReadSquareWriteNode(ctxLevel, coord, l.getLocal(), 0);
}
if (valExpr instanceof NonLocalVariableSquareNode) {
throw new NotYetImplementedException(
"a missing read/square/write combination, used in a benchmark?");
}

if (valExpr instanceof UninitializedMessageSendNode) {
UninitializedMessageSendNode val = (UninitializedMessageSendNode) valExpr;
ExpressionNode[] args = val.getArguments();
if (args.length == 1 && args[0] instanceof LocalVariableReadNode) {
LocalVariableReadNode var = (LocalVariableReadNode) args[0];
if (var.getLocal() == variable) {
return new LocalVarReadUnaryMsgWriteNode((Local) variable,
val.getInvocationIdentifier());
}
}
}
} else {
if (valExpr instanceof NonLocalVariableSquareNode nl) {
return variable.getReadSquareWriteNode(ctxLevel, coord,
nl.getLocal(), nl.getContextLevel());
}

if (valExpr instanceof LocalVariableSquareNode l) {
return variable.getReadSquareWriteNode(ctxLevel, coord, l.getLocal(), 0);
}

if (valExpr instanceof UninitializedMessageSendNode) {
UninitializedMessageSendNode val = (UninitializedMessageSendNode) valExpr;
ExpressionNode[] args = val.getArguments();
if (args.length == 1 && args[0] instanceof NonLocalVariableReadNode) {
NonLocalVariableReadNode var = (NonLocalVariableReadNode) args[0];
if (var.getLocal() == variable) {
return new NonLocalVarReadUnaryMsgWriteNode(ctxLevel, (Local) variable,
val.getInvocationIdentifier());
}
}
}
}
return variable.getWriteNode(ctxLevel, valExpr, coord);
}

protected Local getLocal(final SSymbol varName) {
Expand Down Expand Up @@ -451,7 +509,22 @@ public FieldNode getObjectFieldWrite(final SSymbol fieldName, final ExpressionNo
ExpressionNode self = getSelfRead(coord);
if (exp instanceof IntIncrementNode
&& ((IntIncrementNode) exp).doesAccessField(fieldIndex)) {
return new UninitFieldIncNode(self, fieldIndex, coord);
return ((IntIncrementNode) exp).createFieldIncNode(self, fieldIndex, coord);
}

if (exp instanceof AdditionPrim) {
AdditionPrim add = (AdditionPrim) exp;
ExpressionNode rcvr = add.getReceiver();
ExpressionNode arg = add.getArgument();

if (rcvr instanceof FieldReadNode
&& fieldIndex == ((FieldReadNode) rcvr).getFieldIndex()) {
return new UninitIncFieldNode(self, arg, true, fieldIndex, coord);
}
if (arg instanceof FieldReadNode
&& fieldIndex == ((FieldReadNode) arg).getFieldIndex()) {
return new UninitIncFieldNode(self, rcvr, false, fieldIndex, coord);
}
}

return FieldWriteNodeGen.create(fieldIndex, self, exp).initialize(coord);
Expand Down
115 changes: 109 additions & 6 deletions src/trufflesom/compiler/ParserAst.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,36 @@
import bdt.basic.ProgramDefinitionError;
import bdt.inlining.InlinableNodes;
import bdt.tools.structure.StructuralProbe;
import trufflesom.interpreter.nodes.ArgumentReadNode.LocalArgumentReadNode;
import trufflesom.interpreter.nodes.ArgumentReadNode.NonLocalArgumentReadNode;
import trufflesom.interpreter.nodes.ExpressionNode;
import trufflesom.interpreter.nodes.FieldNode;
import trufflesom.interpreter.nodes.FieldNode.FieldReadNode;
import trufflesom.interpreter.nodes.GlobalNode;
import trufflesom.interpreter.nodes.LocalVariableNode.LocalVariableReadNode;
import trufflesom.interpreter.nodes.MessageSendNode;
import trufflesom.interpreter.nodes.NonLocalVariableNode.NonLocalVariableReadNode;
import trufflesom.interpreter.nodes.SequenceNode;
import trufflesom.interpreter.nodes.literals.BlockNode;
import trufflesom.interpreter.nodes.literals.BlockNode.BlockNodeWithContext;
import trufflesom.interpreter.nodes.literals.DoubleLiteralNode;
import trufflesom.interpreter.nodes.literals.GenericLiteralNode;
import trufflesom.interpreter.nodes.literals.IntegerLiteralNode;
import trufflesom.interpreter.nodes.literals.LiteralNode;
import trufflesom.interpreter.nodes.specialized.IntIncrementNodeGen;
import trufflesom.interpreter.nodes.specialized.IfInlinedLiteralNode;
import trufflesom.interpreter.supernodes.GreaterThanIntNodeGen;
import trufflesom.interpreter.supernodes.IntIncrementNodeGen;
import trufflesom.interpreter.supernodes.LessThanIntNodeGen;
import trufflesom.interpreter.supernodes.LocalArgGreaterThanInt;
import trufflesom.interpreter.supernodes.LocalArgLessThanInt;
import trufflesom.interpreter.supernodes.LocalFieldStringEqualsNode;
import trufflesom.interpreter.supernodes.LocalVariableSquareNodeGen;
import trufflesom.interpreter.supernodes.NonLocalFieldStringEqualsNode;
import trufflesom.interpreter.supernodes.NonLocalVariableSquareNodeGen;
import trufflesom.interpreter.supernodes.StringEqualsNodeGen;
import trufflesom.primitives.Primitives;
import trufflesom.vm.Globals;
import trufflesom.vm.NotYetImplementedException;
import trufflesom.vmobjects.SArray;
import trufflesom.vmobjects.SClass;
import trufflesom.vmobjects.SInvokable;
Expand Down Expand Up @@ -255,18 +271,102 @@ protected ExpressionNode binaryMessage(final MethodGenerationContext mgenc,
mgenc.getHolder().getSuperClass(), msg, args, coordWithL);
}

String binSelector = msg.getString();

if (binSelector.equals("*")) {
if (receiver instanceof LocalVariableReadNode rcvr
&& operand instanceof LocalVariableReadNode op) {
if (rcvr.isSameLocal(op)) {
return LocalVariableSquareNodeGen.create(rcvr.getLocal()).initialize(coordWithL);
}
} else if (receiver instanceof NonLocalVariableReadNode rcvr
&& operand instanceof NonLocalVariableReadNode op) {
if (rcvr.isSameLocal(op)) {
assert rcvr.getContextLevel() == op.getContextLevel();
return NonLocalVariableSquareNodeGen.create(
rcvr.getContextLevel(), rcvr.getLocal()).initialize(coordWithL);
}
}
} else if (binSelector.equals("=")) {
if (operand instanceof GenericLiteralNode) {
Object literal = operand.executeGeneric(null);
if (literal instanceof String l) {
if (receiver instanceof FieldReadNode fieldRead) {
ExpressionNode self = fieldRead.getSelf();
if (self instanceof LocalArgumentReadNode selfLocal) {
return new LocalFieldStringEqualsNode(fieldRead.getFieldIndex(),
selfLocal.getArg(), l).initialize(coordWithL);
} else if (self instanceof NonLocalArgumentReadNode arg) {
return new NonLocalFieldStringEqualsNode(fieldRead.getFieldIndex(),
arg.getArg(), arg.getContextLevel(), l).initialize(coordWithL);
} else {
throw new NotYetImplementedException();
}
}

return StringEqualsNodeGen.create(l, receiver).initialize(coordWithL);
}
}

if (receiver instanceof GenericLiteralNode) {
Object literal = receiver.executeGeneric(null);
if (literal instanceof String l) {
if (operand instanceof FieldReadNode fieldRead) {
ExpressionNode self = fieldRead.getSelf();
if (self instanceof LocalArgumentReadNode selfArg) {
return new LocalFieldStringEqualsNode(fieldRead.getFieldIndex(),
selfArg.getArg(), l).initialize(coordWithL);
} else if (self instanceof NonLocalArgumentReadNode) {
NonLocalArgumentReadNode arg = (NonLocalArgumentReadNode) self;
return new NonLocalFieldStringEqualsNode(fieldRead.getFieldIndex(),
arg.getArg(), arg.getContextLevel(), l).initialize(coordWithL);
} else {
throw new NotYetImplementedException();
}
}

return StringEqualsNodeGen.create(l, operand).initialize(coordWithL);
}
}
} else if (operand instanceof IntegerLiteralNode lit) {
if (binSelector.equals("+")) {
return IntIncrementNodeGen.create(lit.executeLong(null), false, receiver)
.initialize(coordWithL);
}
if (binSelector.equals("-")) {
return IntIncrementNodeGen.create(-lit.executeLong(null), true, receiver)
.initialize(coordWithL);
}
if (binSelector.equals(">")) {
if (receiver instanceof LocalArgumentReadNode rcvr) {
return new LocalArgGreaterThanInt(rcvr.getArg(),
lit.executeLong(null)).initialize(coordWithL);
}

return GreaterThanIntNodeGen.create(lit.executeLong(null), receiver)
.initialize(coordWithL);
}
if (binSelector.equals("<")) {
if (receiver instanceof LocalArgumentReadNode rcvr) {
return new LocalArgLessThanInt(rcvr.getArg(),
lit.executeLong(null)).initialize(coordWithL);
}

return LessThanIntNodeGen.create(lit.executeLong(null), receiver)
.initialize(coordWithL);
}
}

ExpressionNode inlined =
inlinableNodes.inline(msg, args, mgenc, coordWithL);
if (inlined != null) {
assert !isSuperSend;
return inlined;
}

if (msg.getString().equals("+") && operand instanceof IntegerLiteralNode) {
IntegerLiteralNode lit = (IntegerLiteralNode) operand;
if (lit.executeLong(null) == 1) {
return IntIncrementNodeGen.create(receiver);
}
if (msg.getString().equals("+") && operand instanceof IntegerLiteralNode lit) {
long value = lit.executeLong(null);
return IntIncrementNodeGen.create(value, false, receiver);
}
return MessageSendNode.create(msg, args, coordWithL);
}
Expand Down Expand Up @@ -299,6 +399,9 @@ protected ExpressionNode keywordMessage(final MethodGenerationContext mgenc,
ExpressionNode inlined = inlinableNodes.inline(msg, args, mgenc, coodWithL);
if (inlined != null) {
assert !isSuperSend;
if (args.length == 2 && inlined instanceof IfInlinedLiteralNode) {
return ((IfInlinedLiteralNode) inlined).asIsNilIfTrueIfPossible();
}
return inlined;
}

Expand Down
Loading