Skip to content

Commit ba8a97d

Browse files
committed
No more specializeForInterpretation. All specialization is part of IRBuilding
1 parent fe45893 commit ba8a97d

14 files changed

+43
-98
lines changed

core/src/main/java/org/jruby/ir/IRBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ private Operand buildAttrAssign(final AttrAssignNode attrAssignNode, IRScope s)
839839
List<Operand> args = new ArrayList<>();
840840
Node argsNode = attrAssignNode.getArgsNode();
841841
Operand lastArg = (argsNode == null) ? manager.getNil() : buildAttrAssignCallArgs(args, argsNode, s);
842-
addInstr(s, new AttrAssignInstr(obj, attrAssignNode.getName(), args.toArray(new Operand[args.size()])));
842+
addInstr(s, AttrAssignInstr.create(obj, attrAssignNode.getName(), args.toArray(new Operand[args.size()])));
843843
return lastArg;
844844
}
845845

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

core/src/main/java/org/jruby/ir/IRScope.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,6 @@ protected Instr[] prepareInstructions() {
486486
// FIXME: Can be removed once ipc and rpc are stored in table(s) in IC
487487
Instr newInstr = instr.clone(cloneInfo);
488488

489-
// FIXME: Can be removed once noresult and attrassign properly specialize at IRBuild time.
490-
if (newInstr instanceof Specializeable) {
491-
newInstr = ((Specializeable) newInstr).specializeForInterpretation();
492-
}
493-
494489
newInstr.setIPC(ipc);
495490
newInstrs.add(newInstr);
496491
ipc++;

core/src/main/java/org/jruby/ir/instructions/AttrAssignInstr.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
// Instruction representing Ruby code of the form: "a[i] = 5"
1616
// which is equivalent to: a.[](i,5)
1717
public class AttrAssignInstr extends NoResultCallInstr {
18-
public AttrAssignInstr(Operand obj, String attr, Operand[] args) {
19-
super(Operation.ATTR_ASSIGN, CallType.UNKNOWN, attr, obj, args, null);
18+
public static AttrAssignInstr create(Operand obj, String attr, Operand[] args) {
19+
if (!containsArgSplat(args) && args.length == 1) {
20+
return new OneArgOperandAttrAssignInstr(obj, attr, args);
21+
}
22+
23+
return new AttrAssignInstr(obj, attr, args);
2024
}
2125

22-
public AttrAssignInstr(AttrAssignInstr instr) {
23-
this(instr.getReceiver(), instr.getName(), instr.getCallArgs());
26+
public AttrAssignInstr(Operand obj, String attr, Operand[] args) {
27+
super(Operation.ATTR_ASSIGN, CallType.UNKNOWN, attr, obj, args, null);
2428
}
2529

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

42-
@Override
43-
public CallBase specializeForInterpretation() {
44-
Operand[] callArgs = getCallArgs();
45-
if (containsArgSplat(callArgs)) return this;
46-
47-
switch (callArgs.length) {
48-
case 1:
49-
return new OneArgOperandAttrAssignInstr(this);
50-
}
51-
return this;
52-
}
53-
5446
@Override
5547
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope dynamicScope, IRubyObject self, Object[] temp) {
5648
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currScope, dynamicScope, temp);

core/src/main/java/org/jruby/ir/instructions/CallBase.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

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

21-
public abstract class CallBase extends Instr implements Specializeable, ClosureAcceptingInstr {
21+
public abstract class CallBase extends Instr implements ClosureAcceptingInstr {
2222
private static long callSiteCounter = 1;
2323

2424
public final long callSiteId;
@@ -211,15 +211,6 @@ public boolean computeScopeFlags(IRScope scope) {
211211

212212
return modifiedScope;
213213
}
214-
/**
215-
* Interpreter can ask the instruction if it knows how to make a more
216-
* efficient instruction for direct interpretation.
217-
*
218-
* @return itself or more efficient but semantically equivalent instr
219-
*/
220-
public CallBase specializeForInterpretation() {
221-
return this;
222-
}
223214

224215
@Override
225216
public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {

core/src/main/java/org/jruby/ir/instructions/CallInstr.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void updateResult(Variable v) {
6868
}
6969

7070
public Instr discardResult() {
71-
return new NoResultCallInstr(Operation.NORESULT_CALL, getCallType(), getName(), getReceiver(), getCallArgs(), closure);
71+
return NoResultCallInstr.create(getCallType(), getName(), getReceiver(), getCallArgs(), closure);
7272
}
7373

7474
@Override

core/src/main/java/org/jruby/ir/instructions/ClassSuperInstr.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ public Instr discardResult() {
3232
return this;
3333
}
3434

35-
@Override
36-
public CallBase specializeForInterpretation() {
37-
return this;
38-
}
39-
4035
@Override
4136
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
4237
IRubyObject[] args = prepareArguments(context, self, getCallArgs(), currScope, currDynScope, temp);

core/src/main/java/org/jruby/ir/instructions/ConstMissingInstr.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ public void updateResult(Variable v) {
4545
this.result = v;
4646
}
4747

48-
// we don't want to convert const_missing to an actual call
49-
@Override
50-
public CallBase specializeForInterpretation() {
51-
return this;
52-
}
53-
5448
@Override
5549
public Instr clone(CloneInfo ii) {
5650
return new ConstMissingInstr(ii.getRenamedVariable(result), receiver.cloneForInlining(ii), missingConst);

core/src/main/java/org/jruby/ir/instructions/InstanceSuperInstr.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ public Instr discardResult() {
3535
return this;
3636
}
3737

38-
@Override
39-
public CallBase specializeForInterpretation() {
40-
return this;
41-
}
42-
4338
@Override
4439
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
4540
IRubyObject[] args = prepareArguments(context, self, getCallArgs(), currScope, currDynScope, temp);

core/src/main/java/org/jruby/ir/instructions/NoResultCallInstr.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88
import org.jruby.runtime.CallType;
99

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

15-
public NoResultCallInstr(Operation op, NoResultCallInstr instr) {
16-
this(op, instr.getCallType(), instr.getName(), instr.receiver, instr.arguments, instr.closure);
20+
public NoResultCallInstr(Operation op, CallType callType, String name, Operand receiver, Operand[] args, Operand closure) {
21+
super(op, callType, name, receiver, args, closure);
1722
}
1823

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

25-
@Override
26-
public CallBase specializeForInterpretation() {
27-
Operand[] callArgs = getCallArgs();
28-
if (hasClosure() || containsArgSplat(callArgs)) return this;
29-
30-
switch (callArgs.length) {
31-
// case 0:
32-
// return new ZeroOperandArgNoBlockNoResultCallInstr(this);
33-
case 1:
34-
// if (isAllFixnums()) return new OneFixnumArgNoBlockNoResultCallInstr(this);
35-
36-
return new OneOperandArgNoBlockNoResultCallInstr(this);
37-
}
38-
return this;
39-
}
40-
4130
@Override
4231
public void visit(IRVisitor visitor) {
4332
visitor.NoResultCallInstr(this);

core/src/main/java/org/jruby/ir/instructions/Specializeable.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)