Skip to content

Commit

Permalink
No more specializeForInterpretation. All specialization is part of IR…
Browse files Browse the repository at this point in the history
…Building
  • Loading branch information
enebo committed Jan 5, 2015
1 parent fe45893 commit ba8a97d
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 98 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -839,7 +839,7 @@ private Operand buildAttrAssign(final AttrAssignNode attrAssignNode, IRScope s)
List<Operand> args = new ArrayList<>();
Node argsNode = attrAssignNode.getArgsNode();
Operand lastArg = (argsNode == null) ? manager.getNil() : buildAttrAssignCallArgs(args, argsNode, s);
addInstr(s, new AttrAssignInstr(obj, attrAssignNode.getName(), args.toArray(new Operand[args.size()])));
addInstr(s, AttrAssignInstr.create(obj, attrAssignNode.getName(), args.toArray(new Operand[args.size()])));
return lastArg;
}

Expand All @@ -848,7 +848,7 @@ public Operand buildAttrAssignAssignment(Node node, IRScope s, Operand value) {
Operand obj = build(attrAssignNode.getReceiverNode(), s);
Operand[] args = setupCallArgs(attrAssignNode.getArgsNode(), s);
args = addArg(args, value);
addInstr(s, new AttrAssignInstr(obj, attrAssignNode.getName(), args));
addInstr(s, AttrAssignInstr.create(obj, attrAssignNode.getName(), args));
return value;
}

Expand Down
5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -486,11 +486,6 @@ protected Instr[] prepareInstructions() {
// FIXME: Can be removed once ipc and rpc are stored in table(s) in IC
Instr newInstr = instr.clone(cloneInfo);

// FIXME: Can be removed once noresult and attrassign properly specialize at IRBuild time.
if (newInstr instanceof Specializeable) {
newInstr = ((Specializeable) newInstr).specializeForInterpretation();
}

newInstr.setIPC(ipc);
newInstrs.add(newInstr);
ipc++;
Expand Down
24 changes: 8 additions & 16 deletions core/src/main/java/org/jruby/ir/instructions/AttrAssignInstr.java
Expand Up @@ -15,12 +15,16 @@
// Instruction representing Ruby code of the form: "a[i] = 5"
// which is equivalent to: a.[](i,5)
public class AttrAssignInstr extends NoResultCallInstr {
public AttrAssignInstr(Operand obj, String attr, Operand[] args) {
super(Operation.ATTR_ASSIGN, CallType.UNKNOWN, attr, obj, args, null);
public static AttrAssignInstr create(Operand obj, String attr, Operand[] args) {
if (!containsArgSplat(args) && args.length == 1) {
return new OneArgOperandAttrAssignInstr(obj, attr, args);
}

return new AttrAssignInstr(obj, attr, args);
}

public AttrAssignInstr(AttrAssignInstr instr) {
this(instr.getReceiver(), instr.getName(), instr.getCallArgs());
public AttrAssignInstr(Operand obj, String attr, Operand[] args) {
super(Operation.ATTR_ASSIGN, CallType.UNKNOWN, attr, obj, args, null);
}

@Override
Expand All @@ -39,18 +43,6 @@ public Instr clone(CloneInfo ii) {
return new AttrAssignInstr(receiver.cloneForInlining(ii), getName(), cloneCallArgs(ii));
}

@Override
public CallBase specializeForInterpretation() {
Operand[] callArgs = getCallArgs();
if (containsArgSplat(callArgs)) return this;

switch (callArgs.length) {
case 1:
return new OneArgOperandAttrAssignInstr(this);
}
return this;
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope dynamicScope, IRubyObject self, Object[] temp) {
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currScope, dynamicScope, temp);
Expand Down
11 changes: 1 addition & 10 deletions core/src/main/java/org/jruby/ir/instructions/CallBase.java
Expand Up @@ -18,7 +18,7 @@

import static org.jruby.ir.IRFlags.*;

public abstract class CallBase extends Instr implements Specializeable, ClosureAcceptingInstr {
public abstract class CallBase extends Instr implements ClosureAcceptingInstr {
private static long callSiteCounter = 1;

public final long callSiteId;
Expand Down Expand Up @@ -211,15 +211,6 @@ public boolean computeScopeFlags(IRScope scope) {

return modifiedScope;
}
/**
* Interpreter can ask the instruction if it knows how to make a more
* efficient instruction for direct interpretation.
*
* @return itself or more efficient but semantically equivalent instr
*/
public CallBase specializeForInterpretation() {
return this;
}

@Override
public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
Expand Down
Expand Up @@ -68,7 +68,7 @@ public void updateResult(Variable v) {
}

public Instr discardResult() {
return new NoResultCallInstr(Operation.NORESULT_CALL, getCallType(), getName(), getReceiver(), getCallArgs(), closure);
return NoResultCallInstr.create(getCallType(), getName(), getReceiver(), getCallArgs(), closure);
}

@Override
Expand Down
Expand Up @@ -32,11 +32,6 @@ public Instr discardResult() {
return this;
}

@Override
public CallBase specializeForInterpretation() {
return this;
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
IRubyObject[] args = prepareArguments(context, self, getCallArgs(), currScope, currDynScope, temp);
Expand Down
Expand Up @@ -45,12 +45,6 @@ public void updateResult(Variable v) {
this.result = v;
}

// we don't want to convert const_missing to an actual call
@Override
public CallBase specializeForInterpretation() {
return this;
}

@Override
public Instr clone(CloneInfo ii) {
return new ConstMissingInstr(ii.getRenamedVariable(result), receiver.cloneForInlining(ii), missingConst);
Expand Down
Expand Up @@ -35,11 +35,6 @@ public Instr discardResult() {
return this;
}

@Override
public CallBase specializeForInterpretation() {
return this;
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
IRubyObject[] args = prepareArguments(context, self, getCallArgs(), currScope, currDynScope, temp);
Expand Down
Expand Up @@ -8,12 +8,17 @@
import org.jruby.runtime.CallType;

public class NoResultCallInstr extends CallBase {
public NoResultCallInstr(Operation op, CallType callType, String name, Operand receiver, Operand[] args, Operand closure) {
super(op, callType, name, receiver, args, closure);
// FIXME: Removed results undoes specialized callinstrs. Audit how often and what and make equalivalent versions here.
public static NoResultCallInstr create(CallType callType, String name, Operand receiver, Operand[] args, Operand closure) {
if (closure == null && !containsArgSplat(args) && args.length == 1) {
return new OneOperandArgNoBlockNoResultCallInstr(callType, name, receiver, args, closure);
}

return new NoResultCallInstr(Operation.NORESULT_CALL, callType, name, receiver, args, closure);
}

public NoResultCallInstr(Operation op, NoResultCallInstr instr) {
this(op, instr.getCallType(), instr.getName(), instr.receiver, instr.arguments, instr.closure);
public NoResultCallInstr(Operation op, CallType callType, String name, Operand receiver, Operand[] args, Operand closure) {
super(op, callType, name, receiver, args, closure);
}

@Override
Expand All @@ -22,22 +27,6 @@ public Instr clone(CloneInfo ii) {
cloneCallArgs(ii), closure == null ? null : closure.cloneForInlining(ii));
}

@Override
public CallBase specializeForInterpretation() {
Operand[] callArgs = getCallArgs();
if (hasClosure() || containsArgSplat(callArgs)) return this;

switch (callArgs.length) {
// case 0:
// return new ZeroOperandArgNoBlockNoResultCallInstr(this);
case 1:
// if (isAllFixnums()) return new OneFixnumArgNoBlockNoResultCallInstr(this);

return new OneOperandArgNoBlockNoResultCallInstr(this);
}
return this;
}

@Override
public void visit(IRVisitor visitor) {
visitor.NoResultCallInstr(this);
Expand Down
17 changes: 0 additions & 17 deletions core/src/main/java/org/jruby/ir/instructions/Specializeable.java

This file was deleted.

Expand Up @@ -45,11 +45,6 @@ public Instr discardResult() {
return this;
}

@Override
public CallBase specializeForInterpretation() {
return this;
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
IRubyObject[] args = prepareArguments(context, self, getCallArgs(), currScope, currDynScope, temp);
Expand Down
@@ -1,21 +1,28 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.instructions.AttrAssignInstr;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.*;
import org.jruby.runtime.builtin.IRubyObject;

public class OneArgOperandAttrAssignInstr extends AttrAssignInstr {
public OneArgOperandAttrAssignInstr(AttrAssignInstr instr) {
super(instr);
public OneArgOperandAttrAssignInstr(Operand obj, String attr, Operand[] args) {
super(obj, attr, args);
}

@Override
public String toString() {
return super.toString() + "{1O}";
}

@Override
public Instr clone(CloneInfo ii) {
return new OneArgOperandAttrAssignInstr(receiver.cloneForInlining(ii), getName(), cloneCallArgs(ii));
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope dynamicScope, IRubyObject self, Object[] temp) {
Operand[] args = getCallArgs();
Expand Down
@@ -1,16 +1,19 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.Operation;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.instructions.NoResultCallInstr;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.CallType;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class OneOperandArgNoBlockNoResultCallInstr extends NoResultCallInstr {
public OneOperandArgNoBlockNoResultCallInstr(NoResultCallInstr call) {
super(Operation.NORESULT_CALL_1O, call);
public OneOperandArgNoBlockNoResultCallInstr(CallType callType, String name, Operand receiver, Operand[] args, Operand closure) {
super(Operation.NORESULT_CALL_1O, callType, name, receiver, args, closure);
}

@Override
Expand All @@ -22,6 +25,12 @@ public Operand getArg1() {
return getCallArgs()[0];
}

@Override
public Instr clone(CloneInfo ii) {
return new OneOperandArgNoBlockNoResultCallInstr(getCallType(), getName(), receiver.cloneForInlining(ii),
cloneCallArgs(ii), closure == null ? null : closure.cloneForInlining(ii));
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope dynamicScope, IRubyObject self, Object[] temp) {
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currScope, dynamicScope, temp);
Expand Down
Expand Up @@ -139,7 +139,7 @@ private Instr decodeAttrAssignInstr() {
args[i] = d.decodeOperand();
}

return new AttrAssignInstr(op, methAddr, args);
return AttrAssignInstr.create(op, methAddr, args);
}

private Instr decodeCall() {
Expand Down Expand Up @@ -200,7 +200,7 @@ private Instr decodeNoResultCall() {

Operand closure = hasClosureArg ? d.decodeOperand() : null;

return new NoResultCallInstr(Operation.NORESULT_CALL, CallType.fromOrdinal(callTypeOrdinal), methAddr, receiver, args, closure);
return NoResultCallInstr.create(CallType.fromOrdinal(callTypeOrdinal), methAddr, receiver, args, closure);
}

private Instr decodeCopy() {
Expand Down

0 comments on commit ba8a97d

Please sign in to comment.