-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added supernodes for < and > comparsion of an expression or argument …
…with a constant Signed-off-by: Stefan Marr <[email protected]>
- Loading branch information
Showing
6 changed files
with
403 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/trufflesom/src/trufflesom/interpreter/supernodes/compare/GreaterThanIntNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package trufflesom.interpreter.supernodes.compare; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import trufflesom.interpreter.bc.RespecializeException; | ||
import trufflesom.interpreter.nodes.ExpressionNode; | ||
import trufflesom.interpreter.nodes.GenericMessageSendNode; | ||
import trufflesom.interpreter.nodes.MessageSendNode; | ||
import trufflesom.interpreter.nodes.bc.BytecodeLoopNode; | ||
import trufflesom.interpreter.nodes.literals.IntegerLiteralNode; | ||
import trufflesom.interpreter.nodes.nary.UnaryExpressionNode; | ||
import trufflesom.vm.SymbolTable; | ||
import trufflesom.vm.VmSettings; | ||
import trufflesom.vmobjects.SSymbol; | ||
|
||
|
||
public abstract class GreaterThanIntNode extends UnaryExpressionNode { | ||
private final long intValue; | ||
|
||
public GreaterThanIntNode(final long intValue) { | ||
this.intValue = intValue; | ||
} | ||
|
||
@Override | ||
public abstract ExpressionNode getReceiver(); | ||
|
||
@Specialization | ||
public final boolean doLong(final long rcvr) { | ||
return rcvr > intValue; | ||
} | ||
|
||
@Specialization | ||
public final boolean doDouble(final double rcvr) { | ||
return rcvr > intValue; | ||
} | ||
|
||
@Fallback | ||
public final Object makeGenericSend(final VirtualFrame frame, | ||
final Object receiver) { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
return makeGenericSend(SymbolTable.symbolFor(">")).doPreEvaluated(frame, | ||
new Object[] {receiver, intValue}); | ||
} | ||
|
||
@Override | ||
protected GenericMessageSendNode makeGenericSend(final SSymbol selector) { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
GenericMessageSendNode send = MessageSendNode.createGeneric(selector, | ||
new ExpressionNode[] {getReceiver(), new IntegerLiteralNode(intValue)}, sourceCoord); | ||
|
||
if (VmSettings.UseAstInterp) { | ||
replace(send); | ||
send.notifyDispatchInserted(); | ||
return send; | ||
} | ||
|
||
assert getParent() instanceof BytecodeLoopNode : "This node was expected to be a direct child of a `BytecodeLoopNode`."; | ||
throw new RespecializeException(send); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/trufflesom/src/trufflesom/interpreter/supernodes/compare/LessThanIntNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package trufflesom.interpreter.supernodes.compare; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import trufflesom.interpreter.bc.RespecializeException; | ||
import trufflesom.interpreter.nodes.ExpressionNode; | ||
import trufflesom.interpreter.nodes.GenericMessageSendNode; | ||
import trufflesom.interpreter.nodes.MessageSendNode; | ||
import trufflesom.interpreter.nodes.bc.BytecodeLoopNode; | ||
import trufflesom.interpreter.nodes.literals.IntegerLiteralNode; | ||
import trufflesom.interpreter.nodes.nary.UnaryExpressionNode; | ||
import trufflesom.vm.SymbolTable; | ||
import trufflesom.vm.VmSettings; | ||
import trufflesom.vmobjects.SSymbol; | ||
|
||
|
||
public abstract class LessThanIntNode extends UnaryExpressionNode { | ||
private final long intValue; | ||
|
||
public LessThanIntNode(final long intValue) { | ||
this.intValue = intValue; | ||
} | ||
|
||
@Override | ||
public abstract ExpressionNode getReceiver(); | ||
|
||
@Specialization | ||
public final boolean doLong(final long rcvr) { | ||
return rcvr < intValue; | ||
} | ||
|
||
@Specialization | ||
public final boolean doDouble(final double rcvr) { | ||
return rcvr < intValue; | ||
} | ||
|
||
@Fallback | ||
public final Object makeGenericSend(final VirtualFrame frame, | ||
final Object receiver) { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
return makeGenericSend(SymbolTable.symbolFor("<")).doPreEvaluated(frame, | ||
new Object[] {receiver, intValue}); | ||
} | ||
|
||
@Override | ||
protected GenericMessageSendNode makeGenericSend(final SSymbol selector) { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
GenericMessageSendNode send = MessageSendNode.createGeneric(selector, | ||
new ExpressionNode[] {getReceiver(), new IntegerLiteralNode(intValue)}, sourceCoord); | ||
|
||
if (VmSettings.UseAstInterp) { | ||
replace(send); | ||
send.notifyDispatchInserted(); | ||
return send; | ||
} | ||
|
||
assert getParent() instanceof BytecodeLoopNode : "This node was expected to be a direct child of a `BytecodeLoopNode`."; | ||
throw new RespecializeException(send); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
src/trufflesom/src/trufflesom/interpreter/supernodes/compare/LocalArgGreaterThanInt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package trufflesom.interpreter.supernodes.compare; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.UnexpectedResultException; | ||
import trufflesom.bdt.inlining.ScopeAdaptationVisitor; | ||
import trufflesom.bdt.inlining.ScopeAdaptationVisitor.ScopeElement; | ||
import trufflesom.compiler.Variable.Argument; | ||
import trufflesom.interpreter.bc.RespecializeException; | ||
import trufflesom.interpreter.nodes.ArgumentReadNode.LocalArgumentReadNode; | ||
import trufflesom.interpreter.nodes.ExpressionNode; | ||
import trufflesom.interpreter.nodes.GenericMessageSendNode; | ||
import trufflesom.interpreter.nodes.MessageSendNode; | ||
import trufflesom.interpreter.nodes.bc.BytecodeLoopNode; | ||
import trufflesom.interpreter.nodes.literals.IntegerLiteralNode; | ||
import trufflesom.vm.SymbolTable; | ||
import trufflesom.vm.VmSettings; | ||
|
||
|
||
public final class LocalArgGreaterThanInt extends ExpressionNode { | ||
private final Argument arg; | ||
private final int argIdx; | ||
private final long intValue; | ||
|
||
public LocalArgGreaterThanInt(final Argument arg, final long intValue) { | ||
this.arg = arg; | ||
this.argIdx = arg.index; | ||
this.intValue = intValue; | ||
} | ||
|
||
@Override | ||
public Object executeGeneric(final VirtualFrame frame) { | ||
Object arg = frame.getArguments()[argIdx]; | ||
if (arg instanceof Long) { | ||
long argVal = (Long) arg; | ||
return argVal > intValue; | ||
} | ||
|
||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
return fallbackGeneric(frame); | ||
} | ||
|
||
@Override | ||
public Object doPreEvaluated(final VirtualFrame frame, final Object[] args) { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public boolean executeBoolean(final VirtualFrame frame) throws UnexpectedResultException { | ||
Object arg = frame.getArguments()[argIdx]; | ||
if (arg instanceof Long) { | ||
long argVal = (Long) arg; | ||
return argVal > intValue; | ||
} | ||
|
||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
return fallbackBool(frame); | ||
} | ||
|
||
private boolean fallbackBool(final VirtualFrame frame) throws UnexpectedResultException { | ||
Object result = makeGenericSend().doPreEvaluated(frame, | ||
new Object[] {arg, intValue}); | ||
if (result instanceof Boolean) { | ||
return (Boolean) result; | ||
} | ||
throw new UnexpectedResultException(result); | ||
} | ||
|
||
private Object fallbackGeneric(final VirtualFrame frame) { | ||
return makeGenericSend().doPreEvaluated(frame, | ||
new Object[] {arg, intValue}); | ||
} | ||
|
||
protected GenericMessageSendNode makeGenericSend() { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
GenericMessageSendNode send = | ||
MessageSendNode.createGeneric(SymbolTable.symbolFor(">"), new ExpressionNode[] { | ||
new LocalArgumentReadNode(arg), new IntegerLiteralNode(intValue)}, sourceCoord); | ||
|
||
if (VmSettings.UseAstInterp) { | ||
replace(send); | ||
send.notifyDispatchInserted(); | ||
return send; | ||
} | ||
|
||
assert getParent() instanceof BytecodeLoopNode : "This node was expected to be a direct child of a `BytecodeLoopNode`."; | ||
throw new RespecializeException(send); | ||
} | ||
|
||
@Override | ||
public void replaceAfterScopeChange(final ScopeAdaptationVisitor inliner) { | ||
ScopeElement se = inliner.getAdaptedVar(arg); | ||
if (se.var != arg || se.contextLevel < 0) { | ||
if (se.var instanceof Argument arg) { | ||
replace(new LocalArgGreaterThanInt(arg, intValue).initialize(sourceCoord)); | ||
} else { | ||
replace(MessageSendNode.createGeneric(SymbolTable.symbolFor(">"), | ||
new ExpressionNode[] {se.var.getReadNode(se.contextLevel, sourceCoord), | ||
new IntegerLiteralNode(intValue)}, | ||
sourceCoord)); | ||
} | ||
} else { | ||
assert 0 == se.contextLevel; | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
src/trufflesom/src/trufflesom/interpreter/supernodes/compare/LocalArgLessThanInt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package trufflesom.interpreter.supernodes.compare; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.UnexpectedResultException; | ||
import trufflesom.bdt.inlining.ScopeAdaptationVisitor; | ||
import trufflesom.bdt.inlining.ScopeAdaptationVisitor.ScopeElement; | ||
import trufflesom.compiler.Variable.Argument; | ||
import trufflesom.interpreter.bc.RespecializeException; | ||
import trufflesom.interpreter.nodes.ArgumentReadNode.LocalArgumentReadNode; | ||
import trufflesom.interpreter.nodes.ExpressionNode; | ||
import trufflesom.interpreter.nodes.GenericMessageSendNode; | ||
import trufflesom.interpreter.nodes.MessageSendNode; | ||
import trufflesom.interpreter.nodes.bc.BytecodeLoopNode; | ||
import trufflesom.interpreter.nodes.literals.IntegerLiteralNode; | ||
import trufflesom.vm.SymbolTable; | ||
import trufflesom.vm.VmSettings; | ||
|
||
|
||
public final class LocalArgLessThanInt extends ExpressionNode { | ||
private final Argument arg; | ||
private final int argIdx; | ||
private final long intValue; | ||
|
||
public LocalArgLessThanInt(final Argument arg, final long intValue) { | ||
this.arg = arg; | ||
this.argIdx = arg.index; | ||
this.intValue = intValue; | ||
} | ||
|
||
@Override | ||
public Object executeGeneric(final VirtualFrame frame) { | ||
Object arg = frame.getArguments()[argIdx]; | ||
if (arg instanceof Long) { | ||
long argVal = (Long) arg; | ||
return argVal < intValue; | ||
} | ||
|
||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
return fallbackGeneric(frame); | ||
} | ||
|
||
@Override | ||
public Object doPreEvaluated(final VirtualFrame frame, final Object[] args) { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public boolean executeBoolean(final VirtualFrame frame) throws UnexpectedResultException { | ||
Object arg = frame.getArguments()[argIdx]; | ||
if (arg instanceof Long) { | ||
long argVal = (Long) arg; | ||
return argVal < intValue; | ||
} | ||
|
||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
return fallbackBool(frame); | ||
} | ||
|
||
private boolean fallbackBool(final VirtualFrame frame) throws UnexpectedResultException { | ||
Object result = makeGenericSend().doPreEvaluated(frame, | ||
new Object[] {arg, intValue}); | ||
if (result instanceof Boolean) { | ||
return (Boolean) result; | ||
} | ||
throw new UnexpectedResultException(result); | ||
} | ||
|
||
private Object fallbackGeneric(final VirtualFrame frame) { | ||
return makeGenericSend().doPreEvaluated(frame, new Object[] {arg, intValue}); | ||
} | ||
|
||
protected GenericMessageSendNode makeGenericSend() { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
GenericMessageSendNode send = | ||
MessageSendNode.createGeneric(SymbolTable.symbolFor("<"), new ExpressionNode[] { | ||
new LocalArgumentReadNode(arg), new IntegerLiteralNode(intValue)}, sourceCoord); | ||
|
||
if (VmSettings.UseAstInterp) { | ||
replace(send); | ||
send.notifyDispatchInserted(); | ||
return send; | ||
} | ||
|
||
assert getParent() instanceof BytecodeLoopNode : "This node was expected to be a direct child of a `BytecodeLoopNode`."; | ||
throw new RespecializeException(send); | ||
} | ||
|
||
@Override | ||
public void replaceAfterScopeChange(final ScopeAdaptationVisitor inliner) { | ||
ScopeElement se = inliner.getAdaptedVar(arg); | ||
if (se.var != arg || se.contextLevel < 0) { | ||
if (se.var instanceof Argument a) { | ||
replace(new LocalArgLessThanInt(a, intValue).initialize(sourceCoord)); | ||
} else { | ||
replace(MessageSendNode.createGeneric(SymbolTable.symbolFor("<"), | ||
new ExpressionNode[] {se.var.getReadNode(se.contextLevel, sourceCoord), | ||
new IntegerLiteralNode(intValue)}, | ||
sourceCoord)); | ||
} | ||
} else { | ||
assert 0 == se.contextLevel; | ||
} | ||
} | ||
} |
Oops, something went wrong.