Skip to content

Commit

Permalink
Revert "Eliminate most single-element Operand[] in IR."
Browse files Browse the repository at this point in the history
This reverts commit ab235e2.

Too many paths still want Operand[] so we will instead structure
Instr to support many arities and create Operand[] on demand. It
is largely used only by optimization passes now, which run async.
headius committed Jul 27, 2015
1 parent 2f9d8ed commit 4962391
Showing 55 changed files with 135 additions and 155 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/AliasInstr.java
Original file line number Diff line number Diff line change
@@ -57,10 +57,10 @@ public void visit(IRVisitor visitor) {
}

public Operand getNewName() {
return getOperands()[0];
return operands[0];
}

public Operand getOldName() {
return getOperands()[1];
return operands[1];
}
}
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public static BacktickInstr decode(IRReaderDecoder d) {
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
RubyString newString = context.runtime.newString();

for (Operand p: getOperands()) {
for (Operand p: operands) {
RubyBasicObject piece = (RubyBasicObject) p.retrieve(context, self, currScope, currDynScope, temp);
newString.append19((piece instanceof RubyString) ? (RubyString) piece : piece.to_s());
}
Original file line number Diff line number Diff line change
@@ -13,15 +13,17 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

import java.util.Map;

public class BlockGivenInstr extends ResultBaseInstr implements FixedArityInstr {
public BlockGivenInstr(Variable result, Operand block) {
super(Operation.BLOCK_GIVEN, result, block);
super(Operation.BLOCK_GIVEN, result, new Operand[] {block});

assert result != null: "BlockGivenInstr result is null";
}

public Operand getBlockArg() {
return getSingleOperand();
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -10,6 +10,6 @@ public BranchInstr(Operation op, Operand[] operands) {
}

public Label getJumpTarget() {
return (Label) getOperands()[0];
return (Label) operands[0];
}
}
7 changes: 5 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BreakInstr.java
Original file line number Diff line number Diff line change
@@ -5,13 +5,16 @@
import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.StringLiteral;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.InlineCloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;

import java.util.Map;

// NOTE: breaks that jump out of while/until loops would have
// been transformed by the IR building into an ordinary jump.
//
@@ -35,7 +38,7 @@ public class BreakInstr extends Instr implements FixedArityInstr {
private final String scopeName; // Primarily a debugging aid

public BreakInstr(Operand returnValue, String scopeName) {
super(Operation.BREAK, returnValue);
super(Operation.BREAK, new Operand[] { returnValue });
this.scopeName = scopeName;
}

@@ -44,7 +47,7 @@ public String getScopeName() {
}

public Operand getReturnValue() {
return getSingleOperand();
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

import java.util.Map;

// This represents an array that is used solely during arguments construction
// * Array + Splat ([1,2,3], *[5,6,7])
// This used to be an operand, but since to_a can be called as part of
@@ -27,11 +29,11 @@ public BuildCompoundArrayInstr(Variable result, Operand a1, Operand a2, boolean
}

public Operand getAppendingArg() {
return getOperands()[0];
return operands[0];
}

public Operand getAppendedArg() {
return getOperands()[1];
return operands[1];
}

public boolean isArgsPush() { return isArgsPush; }
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
ByteList bytes = new ByteList();
bytes.setEncoding(encoding);
RubyString str = RubyString.newStringShared(context.runtime, bytes, StringSupport.CR_7BIT);
for (Operand p : getOperands()) {
for (Operand p : operands) {
if ((p instanceof StringLiteral) && (isSameEncodingAndCodeRange(str, (StringLiteral)p))) {
str.getByteList().append(((StringLiteral)p).bytelist);
str.setCodeRange(((StringLiteral)p).getCodeRange());
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public BuildDynRegExpInstr(Variable result, Operand[] pieces, RegexpOptions opti
}

public Operand[] getPieces() {
return getOperands();
return operands;
}

public RegexpOptions getOptions() {
@@ -57,10 +57,10 @@ public Instr clone(CloneInfo ii) {
}

private RubyString[] retrievePieces(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
int length = getOperands().length;
int length = operands.length;
RubyString[] strings = new RubyString[length];
for (int i = 0; i < length; i++) {
strings[i] = (RubyString) getOperands()[i].retrieve(context, self, currScope, currDynScope, temp);
strings[i] = (RubyString) operands[i].retrieve(context, self, currScope, currDynScope, temp);
}
return strings;
}
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ public class BuildLambdaInstr extends ResultBaseInstr implements FixedArityInstr
private final int line;

public BuildLambdaInstr(Variable result, Operand lambdaBody, String file, int line) {
super(Operation.LAMBDA, result, lambdaBody);
super(Operation.LAMBDA, result, new Operand[] { lambdaBody });

this.file = file;
this.line = line;
@@ -49,11 +49,11 @@ public Instr clone(CloneInfo ii) {
}

public Operand getLambdaBody() {
return getSingleOperand();
return operands[0];
}

public Operand getClosureArg() {
return getSingleOperand();
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -28,11 +28,11 @@ public BuildRangeInstr(Variable result, Operand begin, Operand end, boolean excl
}

public Operand getBegin() {
return getOperands()[0];
return operands[0];
}

public Operand getEnd() {
return getOperands()[1];
return operands[1];
}

public boolean isExclusive() {
Original file line number Diff line number Diff line change
@@ -16,11 +16,11 @@
// Represents a splat value in Ruby code: *array
public class BuildSplatInstr extends ResultBaseInstr {
public BuildSplatInstr(Variable result, Operand array) {
super(Operation.BUILD_SPLAT, result, array);
super(Operation.BUILD_SPLAT, result, new Operand[] { array });
}

public Operand getArray() {
return getSingleOperand();
return operands[0];
}

@Override
18 changes: 9 additions & 9 deletions core/src/main/java/org/jruby/ir/instructions/CallBase.java
Original file line number Diff line number Diff line change
@@ -91,23 +91,23 @@ public String getName() {

/** From interface ClosureAcceptingInstr */
public Operand getClosureArg() {
return hasClosure ? getOperands()[argsCount + 1] : null;
return hasClosure ? operands[argsCount + 1] : null;
}

public Operand getClosureArg(Operand ifUnspecified) {
return hasClosure ? getClosureArg() : ifUnspecified;
}

public Operand getReceiver() {
return getOperands()[0];
return operands[0];
}

/**
* This getter is potentially unsafe if you do not know you have >=1 arguments to the call. It may return
* null of the closure argument from operands.
*/
public Operand getArg1() {
return getOperands()[1]; // operands layout: receiver, args*, closure
return operands[1]; // operands layout: receiver, args*, closure
}

// FIXME: Maybe rename this.
@@ -119,7 +119,7 @@ public int getArgsCount() {
public Operand[] getCallArgs() {
Operand[] callArgs = new Operand[argsCount];

System.arraycopy(getOperands(), 1, callArgs, 0, argsCount);
System.arraycopy(operands, 1, callArgs, 0, argsCount);

return callArgs;
}
@@ -236,14 +236,14 @@ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
super.simplifyOperands(valueMap, force);

// Recompute containsArgSplat flag
containsArgSplat = containsArgSplat(getOperands()); // also checking receiver but receiver can never be a splat
containsArgSplat = containsArgSplat(operands); // also checking receiver but receiver can never be a splat
flagsComputed = false; // Forces recomputation of flags
}

public Operand[] cloneCallArgs(CloneInfo ii) {
Operand[] clonedArgs = new Operand[argsCount];
for (int i = 0; i < argsCount; i++) {
clonedArgs[i] = getOperands()[i+1].cloneForInlining(ii); // +1 for receiver being operands[0]
clonedArgs[i] = operands[i+1].cloneForInlining(ii); // +1 for receiver being operands[0]
}

return clonedArgs;
@@ -429,7 +429,7 @@ protected IRubyObject[] prepareArgumentsSimple(ThreadContext context, IRubyObjec
IRubyObject[] newArgs = new IRubyObject[argsCount];

for (int i = 0; i < argsCount; i++) { // receiver is operands[0]
newArgs[i] = (IRubyObject) getOperands()[i+1].retrieve(context, self, currScope, currDynScope, temp);
newArgs[i] = (IRubyObject) operands[i+1].retrieve(context, self, currScope, currDynScope, temp);
}

return newArgs;
@@ -443,8 +443,8 @@ protected IRubyObject[] prepareArgumentsComplex(ThreadContext context, IRubyObje
// optimize for CallInstr which has splats only in the first position, we could do that.
List<IRubyObject> argList = new ArrayList<>(argsCount * 2);
for (int i = 0; i < argsCount; i++) { // receiver is operands[0]
IRubyObject rArg = (IRubyObject) getOperands()[i+1].retrieve(context, self, currScope, currDynScope, temp);
if (getOperands()[i+1] instanceof Splat) {
IRubyObject rArg = (IRubyObject) operands[i+1].retrieve(context, self, currScope, currDynScope, temp);
if (operands[i+1] instanceof Splat) {
RubyArray array = (RubyArray) rArg;
for (int j = 0; j < array.size(); j++) {
argList.add(array.eltOk(j));
Original file line number Diff line number Diff line change
@@ -19,15 +19,15 @@ public class CheckArgsArrayArityInstr extends Instr implements FixedArityInstr {
public final boolean rest;

public CheckArgsArrayArityInstr(Operand argsArray, int required, int opt, boolean rest) {
super(Operation.CHECK_ARGS_ARRAY_ARITY, argsArray);
super(Operation.CHECK_ARGS_ARRAY_ARITY, new Operand[] { argsArray });

this.required = required;
this.opt = opt;
this.rest = rest;
}

public Operand getArgsArray() {
return getSingleOperand();
return operands[0];
}

@Override
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/CopyInstr.java
Original file line number Diff line number Diff line change
@@ -16,15 +16,15 @@

public class CopyInstr extends ResultBaseInstr implements FixedArityInstr {
public CopyInstr(Operation op, Variable result, Operand source) {
super(op, result, source);
super(op, result, new Operand[] { source });
}

public CopyInstr(Variable result, Operand source) {
this(Operation.COPY, result, source);
}

public Operand getSource() {
return getSingleOperand();
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -31,11 +31,11 @@ public IRClassBody getNewIRClassBody() {
}

public Operand getContainer() {
return getOperands()[0];
return operands[0];
}

public Operand getSuperClass() {
return getOperands()[1];
return operands[1];
}

@Override
Original file line number Diff line number Diff line change
@@ -18,12 +18,12 @@ public class DefineClassMethodInstr extends Instr implements FixedArityInstr {
private final IRMethod method;

public DefineClassMethodInstr(Operand container, IRMethod method) {
super(Operation.DEF_CLASS_METH, container);
super(Operation.DEF_CLASS_METH, new Operand[] { container });
this.method = method;
}

public Operand getContainer() {
return getSingleOperand();
return operands[0];
}

public IRMethod getMethod() {
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ public class DefineMetaClassInstr extends ResultBaseInstr implements FixedArityI
private final IRModuleBody metaClassBody;

public DefineMetaClassInstr(Variable result, Operand object, IRModuleBody metaClassBody) {
super(Operation.DEF_META_CLASS, result, object);
super(Operation.DEF_META_CLASS, result, new Operand[] {object });

assert result != null: "DefineMetaClassInstr result is null";

@@ -29,7 +29,7 @@ public IRModuleBody getMetaClassBody() {
}

public Operand getObject() {
return getSingleOperand();
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public class DefineModuleInstr extends ResultBaseInstr implements FixedArityInst
private final IRModuleBody newIRModuleBody;

public DefineModuleInstr(Variable result, IRModuleBody newIRModuleBody, Operand container) {
super(Operation.DEF_MODULE, result, container);
super(Operation.DEF_MODULE, result, new Operand[] { container });

assert result != null : "DefineModuleInstr result is null";

@@ -31,7 +31,7 @@ public IRModuleBody getNewIRModuleBody() {
}

public Operand getContainer() {
return getSingleOperand();
return operands[0];
}

@Override
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/EQQInstr.java
Original file line number Diff line number Diff line change
@@ -22,11 +22,11 @@ public EQQInstr(Variable result, Operand v1, Operand v2) {
}

public Operand getArg1() {
return getOperands()[0];
return operands[0];
}

public Operand getArg2() {
return getOperands()[1];
return operands[1];
}

@Override
Original file line number Diff line number Diff line change
@@ -10,16 +10,16 @@

public class ExceptionRegionStartMarkerInstr extends Instr implements FixedArityInstr {
public ExceptionRegionStartMarkerInstr(Label firstRescueBlockLabel) {
super(Operation.EXC_REGION_START, firstRescueBlockLabel);
super(Operation.EXC_REGION_START, new Operand[] { firstRescueBlockLabel });
}

public Label getFirstRescueBlockLabel() {
return (Label) getSingleOperand();
return (Label) operands[0];
}

@Override
public Instr clone(CloneInfo ii) {
return new ExceptionRegionStartMarkerInstr(ii.getRenamedLabel((Label) getSingleOperand()));
return new ExceptionRegionStartMarkerInstr(ii.getRenamedLabel((Label) operands[0]));
}

@Override
Original file line number Diff line number Diff line change
@@ -17,11 +17,11 @@ public GVarAliasInstr(Operand newName, Operand oldName) {
}

public Operand getNewName() {
return getOperands()[0];
return operands[0];
}

public Operand getOldName() {
return getOperands()[1];
return operands[1];
}

@Override
Original file line number Diff line number Diff line change
@@ -27,11 +27,11 @@ public GetClassVarContainerModuleInstr(Variable result, Operand startingScope, V
}

public Variable getObject() {
return (Variable) (getOperands().length >= 2 ? getOperands()[1] : null);
return (Variable) (operands.length >= 2 ? operands[1] : null);
}

public Operand getStartingScope() {
return getOperands()[0];
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -21,11 +21,11 @@ public GetGlobalVariableInstr(Variable dest, String gvarName) {
}

public GetGlobalVariableInstr(Variable dest, GlobalVariable gvar) {
super(Operation.GET_GLOBAL_VAR, dest, gvar);
super(Operation.GET_GLOBAL_VAR, dest, new Operand[] { gvar });
}

public GlobalVariable getGVar() {
return (GlobalVariable) getSingleOperand();
return (GlobalVariable) operands[0];
}

public boolean computeScopeFlags(IRScope scope) {
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/GetInstr.java
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ public abstract class GetInstr extends ResultBaseInstr implements FixedArityInst
private final String ref;

public GetInstr(Operation op, Variable result, Operand source, String ref) {
super(op, result, source);
super(op, result, new Operand[] { source });

assert result != null: "" + getClass().getSimpleName() + " result is null";

@@ -22,7 +22,7 @@ public String getRef() {
}

public Operand getSource() {
return getSingleOperand();
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ public class InheritanceSearchConstInstr extends ResultBaseInstr implements Fixe
private volatile transient ConstantCache cache;

public InheritanceSearchConstInstr(Variable result, Operand currentModule, String constName, boolean noPrivateConsts) {
super(Operation.INHERITANCE_SEARCH_CONST, result, currentModule);
super(Operation.INHERITANCE_SEARCH_CONST, result, new Operand[] { currentModule });

assert result != null: "InheritanceSearchConstInstr result is null";

@@ -37,7 +37,7 @@ public InheritanceSearchConstInstr(Variable result, Operand currentModule, Strin
}

public Operand getCurrentModule() {
return getSingleOperand();
return operands[0];
}

public String getConstName() {
27 changes: 1 addition & 26 deletions core/src/main/java/org/jruby/ir/instructions/Instr.java
Original file line number Diff line number Diff line change
@@ -35,8 +35,7 @@
public abstract class Instr {
public static final Operand[] EMPTY_OPERANDS = new Operand[] {};

private Operand singleOperand;
private Operand[] operands;
protected Operand[] operands;
private int ipc; // Interpreter-only: instruction pointer
private int rpc; // Interpreter-only: rescue pointer
private final Operation operation;
@@ -52,13 +51,6 @@ public Instr(Operation operation, Operand[] operands) {
this.operands = operands;
}

public Instr(Operation operation, Operand singleOperand) {
this.ipc = -1;
this.rpc = -1;
this.operation = operation;
this.singleOperand = singleOperand;
}

private static String[] EMPTY_STRINGS = new String[0];
public String[] toStringNonOperandArgs() {
return EMPTY_STRINGS;
@@ -180,10 +172,6 @@ public boolean isDead() {

/* Array of all operands for this instruction */
public Operand[] getOperands() {
Operand[] operands = this.operands;
if (operands != null) return operands;
operands = new Operand[] {singleOperand};
this.operands = operands;
return operands;
}

@@ -275,17 +263,4 @@ public int interpretAndGetNewIPC(ThreadContext context, DynamicScope currDynScop
public void visit(IRVisitor visitor) {
throw new RuntimeException(this.getClass().getSimpleName() + " has no compile logic");
}

public Operand getSingleOperand() {
return singleOperand;
}

public void setSingleOperand(Operand singleOperand) {
this.singleOperand = singleOperand;
this.operands = null;
}

public void setOperands(Operand[] operands) {
this.operands = operands;
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/JumpInstr.java
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ public JumpInstr(Label target) {
}

public JumpInstr(Label target, boolean exitsExcRegion) {
super(Operation.JUMP, target);
super(Operation.JUMP, new Operand[] { target });
this.exitsExcRegion = exitsExcRegion;
}

@@ -25,7 +25,7 @@ public boolean exitsExcRegion() {
}

public Label getJumpTarget() {
return (Label) getSingleOperand();
return (Label) operands[0];
}

@Override
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/LabelInstr.java
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@

public class LabelInstr extends Instr implements FixedArityInstr {
public LabelInstr(Label label) {
super(Operation.LABEL, label);
super(Operation.LABEL, new Operand[] { label });
}

public Label getLabel() {
return (Label) getSingleOperand();
return (Label) operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -27,15 +27,15 @@ public class LexicalSearchConstInstr extends ResultBaseInstr implements FixedAri
private volatile transient ConstantCache cache;

public LexicalSearchConstInstr(Variable result, Operand definingScope, String constName) {
super(Operation.LEXICAL_SEARCH_CONST, result, definingScope);
super(Operation.LEXICAL_SEARCH_CONST, result, new Operand[] { definingScope });

assert result != null: "LexicalSearchConstInstr result is null";

this.constName = constName;
}

public Operand getDefiningScope() {
return getSingleOperand();
return operands[0];
}

public String getConstName() {
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public class LoadLocalVarInstr extends ResultBaseInstr implements FixedArityInst
private final IRScope scope;

public LoadLocalVarInstr(IRScope scope, TemporaryLocalVariable result, LocalVariable lvar) {
super(Operation.BINDING_LOAD, result, lvar);
super(Operation.BINDING_LOAD, result, new Operand[] { lvar });

assert result != null: "LoadLocalVarInstr result is null";

@@ -29,7 +29,7 @@ public LoadLocalVarInstr(IRScope scope, TemporaryLocalVariable result, LocalVari
* computation itself. We just use it as a proxy for its (a) name (b) offset (c) scope-depth.
*/
public LocalVariable getLocalVar() {
return (LocalVariable) getSingleOperand();
return (LocalVariable) operands[0];
}

public IRScope getScope() {
@@ -46,7 +46,7 @@ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {

// SSS FIXME: This feels dirty
public void decrementLVarScopeDepth() {
setSingleOperand(getLocalVar().cloneForDepth(getLocalVar().getScopeDepth()-1));
operands[0] = getLocalVar().cloneForDepth(getLocalVar().getScopeDepth()-1);
}

@Override
Original file line number Diff line number Diff line change
@@ -28,12 +28,12 @@ public ModuleVersionGuardInstr(RubyModule module, int expectedVersion, Operand c

/** The object whose metaclass token has to be verified*/
public Operand getCandidateObject() {
return getOperands()[0];
return operands[0];
}

/** Where to jump if the version assumption fails? */
public Label getFailurePathLabel() {
return (Label) getOperands()[1];
return (Label) operands[1];
}

// FIXME: We should remove this and only save what we care about..live Module cannot be neccesary here?
Original file line number Diff line number Diff line change
@@ -13,15 +13,15 @@ public abstract class MultipleAsgnBase extends ResultBaseInstr {
protected final int index;

public MultipleAsgnBase(Operation op, Variable result, Operand array, int index) {
super(op, result, array);
super(op, result, new Operand[] { array });

assert result != null : "MultipleAsgnBase result is null";

this.index = index;
}

public Operand getArray() {
return getSingleOperand();
return operands[0];
}

public int getIndex() {
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.jruby.ir.instructions;

import org.jruby.ir.Operation;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;

import java.util.Map;
import org.jruby.ir.persistence.IRWriterEncoder;

public abstract class OneOperandBranchInstr extends BranchInstr {
@@ -11,7 +13,7 @@ public OneOperandBranchInstr(Operation op, Operand[] operands) {
}

public Operand getArg1() {
return getOperands()[1];
return operands[1];
}

@Override
Original file line number Diff line number Diff line change
@@ -23,11 +23,11 @@ public ProcessModuleBodyInstr(Variable result, Operand moduleBody, Operand block
}

public Operand getModuleBody() {
return getOperands()[0];
return operands[0];
}

public Operand getBlock() {
return getOperands()[1];
return operands[1];
}

@Override
Original file line number Diff line number Diff line change
@@ -36,11 +36,11 @@ public boolean computeScopeFlags(IRScope scope) {
}

public GlobalVariable getTarget() {
return (GlobalVariable) getOperands()[0];
return (GlobalVariable) operands[0];
}

public Operand getValue() {
return getOperands()[1];
return operands[1];
}

@Override
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/PutInstr.java
Original file line number Diff line number Diff line change
@@ -19,11 +19,11 @@ public String getRef() {
}

public Operand getTarget() {
return getOperands()[0];
return operands[0];
}

public Operand getValue() {
return getOperands()[1];
return operands[1];
}

@Override
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ public class RecordEndBlockInstr extends Instr implements FixedArityInstr {
private final IRScope declaringScope;

public RecordEndBlockInstr(IRScope declaringScope, WrappedIRClosure endBlockClosure) {
super(Operation.RECORD_END_BLOCK, endBlockClosure);
super(Operation.RECORD_END_BLOCK, new Operand[] { endBlockClosure });

this.declaringScope = declaringScope;
}
@@ -27,7 +27,7 @@ public IRScope getDeclaringScope() {
}

public WrappedIRClosure getEndBlockClosure() {
return (WrappedIRClosure) getSingleOperand();
return (WrappedIRClosure) operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -22,13 +22,13 @@
/* Receive the closure argument (either implicit or explicit in Ruby source code) */
public class ReifyClosureInstr extends ResultBaseInstr implements FixedArityInstr {
public ReifyClosureInstr(Variable result, Variable source) {
super(Operation.REIFY_CLOSURE, result, source);
super(Operation.REIFY_CLOSURE, result, new Operand[] { source });

assert result != null: "ReceiveClosureInstr result is null";
}

public Variable getSource() {
return (Variable) getSingleOperand();
return (Variable) operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -26,11 +26,11 @@ public RescueEQQInstr(Variable result, Operand v1, Operand v2) {
}

public Operand getArg1() {
return getOperands()[0];
return operands[0];
}

public Operand getArg2() {
return getOperands()[1];
return operands[1];
}

@Override
Original file line number Diff line number Diff line change
@@ -19,12 +19,6 @@ public ResultBaseInstr(Operation operation, Variable result, Operand[] operands)
this.result = result;
}

public ResultBaseInstr(Operation operation, Variable result, Operand singleOperand) {
super(operation, singleOperand);

this.result = result;
}

@Override
public void encode(IRWriterEncoder e) {
super.encode(e);
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/instructions/ReturnBase.java
Original file line number Diff line number Diff line change
@@ -5,16 +5,16 @@

public abstract class ReturnBase extends Instr {
public ReturnBase(Operation op, Operand returnValue) {
super(op, returnValue);
super(op, new Operand[] { returnValue });

assert returnValue != null : "RETURN must have returnValue operand";
}

public Operand getReturnValue() {
return getSingleOperand();
return operands[0];
}

public void updateReturnValue(Operand val) {
setSingleOperand(val);
operands[0] = val;
}
}
20 changes: 10 additions & 10 deletions core/src/main/java/org/jruby/ir/instructions/RuntimeHelperCall.java
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public RuntimeHelperCall(Variable result, Methods helperMethod, Operand[] args)
}

public Operand[] getArgs() {
return getOperands();
return operands;
}

public Methods getHelperMethod() {
@@ -93,12 +93,12 @@ public IRubyObject callHelper(ThreadContext context, StaticScope currScope, Dyna

switch (helperMethod) {
case IS_DEFINED_NTH_REF:
return IRRuntimeHelpers.isDefinedNthRef(context, (int) ((Fixnum) getOperands()[0]).getValue());
return IRRuntimeHelpers.isDefinedNthRef(context, (int) ((Fixnum) operands[0]).getValue());
case IS_DEFINED_GLOBAL:
return IRRuntimeHelpers.isDefinedGlobal(context, ((StringLiteral) getOperands()[0]).getString());
return IRRuntimeHelpers.isDefinedGlobal(context, ((StringLiteral) operands[0]).getString());
}

Object arg1 = getOperands()[0].retrieve(context, self, currScope, currDynScope, temp);
Object arg1 = operands[0].retrieve(context, self, currScope, currDynScope, temp);

switch (helperMethod) {
case HANDLE_PROPAGATE_BREAK:
@@ -108,20 +108,20 @@ public IRubyObject callHelper(ThreadContext context, StaticScope currScope, Dyna
case HANDLE_BREAK_AND_RETURNS_IN_LAMBDA:
return IRRuntimeHelpers.handleBreakAndReturnsInLambdas(context, scope, currDynScope, arg1, blockType);
case IS_DEFINED_CALL:
return IRRuntimeHelpers.isDefinedCall(context, self, (IRubyObject) arg1, ((StringLiteral) getOperands()[1]).getString());
return IRRuntimeHelpers.isDefinedCall(context, self, (IRubyObject) arg1, ((StringLiteral) operands[1]).getString());
case IS_DEFINED_CONSTANT_OR_METHOD:
return IRRuntimeHelpers.isDefinedConstantOrMethod(context, (IRubyObject) arg1,
((FrozenString) getOperands()[1]).getString());
((FrozenString) operands[1]).getString());
case IS_DEFINED_INSTANCE_VAR:
return IRRuntimeHelpers.isDefinedInstanceVar(context, (IRubyObject) arg1, ((StringLiteral) getOperands()[1]).getString());
return IRRuntimeHelpers.isDefinedInstanceVar(context, (IRubyObject) arg1, ((StringLiteral) operands[1]).getString());
case IS_DEFINED_CLASS_VAR:
return IRRuntimeHelpers.isDefinedClassVar(context, (RubyModule) arg1, ((StringLiteral) getOperands()[1]).getString());
return IRRuntimeHelpers.isDefinedClassVar(context, (RubyModule) arg1, ((StringLiteral) operands[1]).getString());
case IS_DEFINED_SUPER:
return IRRuntimeHelpers.isDefinedSuper(context, (IRubyObject) arg1);
case IS_DEFINED_METHOD:
return IRRuntimeHelpers.isDefinedMethod(context, (IRubyObject) arg1,
((StringLiteral) getOperands()[1]).getString(),
((Boolean) getOperands()[2]).isTrue());
((StringLiteral) operands[1]).getString(),
((Boolean) operands[2]).isTrue());
case MERGE_KWARGS:
return IRRuntimeHelpers.mergeKeywordArguments(context, (IRubyObject) arg1,
(IRubyObject) getArgs()[1].retrieve(context, self, currScope, currDynScope, temp));
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
import org.jruby.runtime.opto.ConstantCache;
import org.jruby.runtime.opto.Invalidator;

import java.util.Map;

// Const search:
// - looks up lexical scopes
// - then inheritance hierarcy if lexical search fails
@@ -28,7 +30,7 @@ public class SearchConstInstr extends ResultBaseInstr implements FixedArityInstr
private volatile transient ConstantCache cache;

public SearchConstInstr(Variable result, String constName, Operand startingScope, boolean noPrivateConsts) {
super(Operation.SEARCH_CONST, result, startingScope);
super(Operation.SEARCH_CONST, result, new Operand[] { startingScope });

assert result != null: "SearchConstInstr result is null";

@@ -38,7 +40,7 @@ public SearchConstInstr(Variable result, String constName, Operand startingScope


public Operand getStartingScope() {
return getSingleOperand();
return operands[0];
}

public String getConstName() {
Original file line number Diff line number Diff line change
@@ -18,15 +18,15 @@ public class SetCapturedVarInstr extends ResultBaseInstr implements FixedArityIn
private final String varName;

public SetCapturedVarInstr(Variable result, Operand match2Result, String varName) {
super(Operation.SET_CAPTURED_VAR, result, match2Result);
super(Operation.SET_CAPTURED_VAR, result, new Operand[] { match2Result });

assert result != null: "SetCapturedVarInstr result is null";

this.varName = varName;
}

public Operand getMatch2Result() {
return getSingleOperand();
return operands[0];
}

public String getVarName() {
Original file line number Diff line number Diff line change
@@ -25,14 +25,14 @@ public StoreLocalVarInstr(IRScope scope, Operand value, LocalVariable lvar) {


public Operand getValue() {
return getOperands()[0];
return operands[0];
}

/** This is the variable that is being stored into in this scope. This variable
* doesn't participate in the computation itself. We just use it as a proxy for
* its (a) name (b) offset (c) scope-depth. */
public LocalVariable getLocalVar() {
return (LocalVariable) getOperands()[1];
return (LocalVariable) operands[1];
}

public IRScope getScope() {
@@ -46,7 +46,7 @@ public String[] toStringNonOperandArgs() {

// SSS FIXME: This feels dirty
public void decrementLVarScopeDepth() {
getOperands()[1] = getLocalVar().cloneForDepth(getLocalVar().getScopeDepth()-1);
operands[1] = getLocalVar().cloneForDepth(getLocalVar().getScopeDepth()-1);
}

/**
@@ -55,7 +55,7 @@ public void decrementLVarScopeDepth() {
*/
@Override
public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
getOperands()[0] = getValue().getSimplifiedOperand(valueMap, force);
operands[0] = getValue().getSimplifiedOperand(valueMap, force);
}

@Override
Original file line number Diff line number Diff line change
@@ -19,11 +19,11 @@
// Ruby exceptions go through RubyKernel.raise (or RubyThread.raise).
public class ThrowExceptionInstr extends Instr implements FixedArityInstr {
public ThrowExceptionInstr(Operand exception) {
super(Operation.THROW, exception);
super(Operation.THROW, new Operand[] { exception });
}

public Operand getException() {
return getSingleOperand();
return operands[0];
}

@Override
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/ToAryInstr.java
Original file line number Diff line number Diff line change
@@ -19,13 +19,13 @@

public class ToAryInstr extends ResultBaseInstr implements FixedArityInstr {
public ToAryInstr(Variable result, Operand array) {
super(Operation.TO_ARY, result, array);
super(Operation.TO_ARY, result, new Operand[] { array });

assert result != null: "ToAryInstr result is null";
}

public Operand getArray() {
return getSingleOperand();
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -19,10 +19,10 @@ public void encode(IRWriterEncoder e) {
}

public Operand getArg1() {
return getOperands()[1];
return operands[1];
}

public Operand getArg2() {
return getOperands()[2];
return operands[2];
}
}
Original file line number Diff line number Diff line change
@@ -19,11 +19,11 @@
public class UndefMethodInstr extends ResultBaseInstr implements FixedArityInstr {
// SSS FIXME: Implicit self arg -- make explicit to not get screwed by inlining!
public UndefMethodInstr(Variable result, Operand methodName) {
super(Operation.UNDEF_METHOD, result, methodName);
super(Operation.UNDEF_METHOD, result, new Operand[] { methodName });
}

public Operand getMethodName() {
return getSingleOperand();
return operands[0];
}

@Override
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/YieldInstr.java
Original file line number Diff line number Diff line change
@@ -27,11 +27,11 @@ public YieldInstr(Variable result, Operand block, Operand arg, boolean unwrapArr
}

public Operand getBlockArg() {
return getOperands()[0];
return operands[0];
}

public Operand getYieldArg() {
return getOperands()[1];
return operands[1];
}

@Override
Original file line number Diff line number Diff line change
@@ -15,11 +15,11 @@ public AluInstr(Operation op, Variable result, Operand a1, Operand a2) {
}

public Operand getArg1() {
return getOperands()[0];
return operands[0];
}

public Operand getArg2() {
return getOperands()[1];
return operands[1];
}

@Override
Original file line number Diff line number Diff line change
@@ -7,10 +7,10 @@

public abstract class BoxInstr extends ResultBaseInstr {
public BoxInstr(Operation op, Variable result, Operand val) {
super(op, result, val);
super(op, result, new Operand[] { val });
}

public Operand getValue() {
return getSingleOperand();
return operands[0];
}
}
Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@

public class UnboxInstr extends ResultBaseInstr {
public UnboxInstr(Operation op, Variable result, Operand value) {
super(op, result, value);
super(op, result, new Operand[] { value });
}

public Operand getValue() {
return getSingleOperand();
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -15,11 +15,11 @@

public class RestoreErrorInfoInstr extends Instr implements FixedArityInstr {
public RestoreErrorInfoInstr(Operand arg) {
super(Operation.RESTORE_ERROR_INFO, arg);
super(Operation.RESTORE_ERROR_INFO, new Operand[] { arg });
}

public Operand getArg() {
return getSingleOperand();
return operands[0];
}

@Override
Original file line number Diff line number Diff line change
@@ -331,7 +331,7 @@ protected static void processBookKeepingOp(ThreadContext context, Instr instr, O
case LABEL:
break;
case EXC_REGION_START:
rescuePCs.push(((Label)instr.getSingleOperand()).getTargetPC());
rescuePCs.push(((Label)instr.getOperands()[0]).getTargetPC());
break;
case EXC_REGION_END:
rescuePCs.pop();

0 comments on commit 4962391

Please sign in to comment.