Skip to content

Commit

Permalink
Unboxing: Minor tweaks and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
subbuss committed Jan 17, 2015
1 parent 80d3fff commit 41e4586
Showing 1 changed file with 25 additions and 28 deletions.
Expand Up @@ -243,13 +243,11 @@ public void applyTransferFunction(Instr i) {
// should ideally be done 'on-demand'. This indicates that this could
// be a backward-flow algo OR that this algo should be run on a
// dataflow graph / SSA graph.
if (srcType == Float.class) {
if (srcType == Float.class || srcType == Fixnum.class) {
unboxedAndDirty = true;
tmpState.unboxedVars.put(dst, srcType);
} else if (srcType == Fixnum.class) {
unboxedAndDirty = true;
tmpState.unboxedVars.put(dst, srcType);
}

tmpState.unboxedVars.put(dst, dstType);
} else if (i instanceof ClosureAcceptingInstr) {
Operand o = ((ClosureAcceptingInstr)i).getClosureArg();
// Process calls specially -- these are what we want to optimize!
Expand All @@ -261,7 +259,7 @@ public void applyTransferFunction(Instr i) {
Operand a = c.getArg1();
Class receiverType = getOperandType(tmpState, r);
Class argType = getOperandType(tmpState, a);
// Optimistically assume that call is an ALU op

if (problem.acceptsArgTypes(m, receiverType, argType)) {
Class unboxedType = problem.getUnboxedType(m, receiverType, argType);
unboxedAndDirty = true;
Expand All @@ -270,7 +268,7 @@ public void applyTransferFunction(Instr i) {
tmpState.unboxedVars.put(dst, dstType);

// If 'r' and 'a' are not already in unboxed forms at this point,
// they will get unboxed after this, because we want to opt. this call
// they will get unboxed after this, because we want to opt. this call.
if (r instanceof Variable) {
tmpState.unboxedVars.put((Variable)r, unboxedType);
}
Expand Down Expand Up @@ -413,34 +411,33 @@ private Operand unboxOperand(UnboxState state, Class reqdType, Map<Variable, Tem
}

return unboxedVar;
} else {
if (arg instanceof Float) {
return new UnboxedFloat(((Float)arg).getValue());
} else if (arg instanceof Fixnum) {
return new UnboxedFixnum(((Fixnum)arg).getValue());
} else if (arg instanceof Boolean) {
return new UnboxedBoolean(((Boolean)arg).isTrue());
}
// This has to be a known operand like (UnboxedBoolean, etc.)
return arg;
} else if (arg instanceof Float) {
return new UnboxedFloat(((Float)arg).getValue());
} else if (arg instanceof Fixnum) {
return new UnboxedFixnum(((Fixnum)arg).getValue());
} else if (arg instanceof Boolean) {
return new UnboxedBoolean(((Boolean)arg).isTrue());
}

// This has to be a known operand like (UnboxedBoolean, etc.)
return arg;
}

private Operand getUnboxedOperand(UnboxState state, Map<Variable, TemporaryLocalVariable> unboxMap, Operand arg) {
if (arg instanceof Variable) {
Variable v = (Variable)arg;
Class unboxedType = state.unboxedVars.get(v);
return unboxedType == null ? arg : getUnboxedVar(unboxedType, unboxMap, v);
} else {
if (arg instanceof Float) {
return new UnboxedFloat(((Float)arg).getValue());
} else if (arg instanceof Fixnum) {
return new UnboxedFixnum(((Fixnum)arg).getValue());
} else if (arg instanceof Boolean) {
return new UnboxedBoolean(((Boolean)arg).isTrue());
}
return arg;
} else if (arg instanceof Float) {
return new UnboxedFloat(((Float)arg).getValue());
} else if (arg instanceof Fixnum) {
return new UnboxedFixnum(((Fixnum)arg).getValue());
} else if (arg instanceof Boolean) {
return new UnboxedBoolean(((Boolean)arg).isTrue());
}

// This has to be a known operand like (UnboxedBoolean, etc.)
return arg;
}

private void boxRequiredVars(Instr i, UnboxState state, Map<Variable, TemporaryLocalVariable> unboxMap, Variable dst, boolean hasRescuer, boolean isDFBarrier, List<Instr> newInstrs) {
Expand Down Expand Up @@ -613,9 +610,10 @@ public void unbox(Map<Variable, TemporaryLocalVariable> unboxMap) {
Operand unboxedSrc = src instanceof Variable ? getUnboxedVar(srcType, unboxMap, (Variable)src) : src;
TemporaryLocalVariable unboxedDst = getUnboxedVar(srcType, unboxMap, dst);
newInstrs.add(new CopyInstr(Operation.COPY, unboxedDst, unboxedSrc));
tmpState.unboxedVars.put(dst, srcType);
unboxedAndDirty = true;
}

tmpState.unboxedVars.put(dst, dstType);
} else if (i instanceof ClosureAcceptingInstr) {
Operand o = ((ClosureAcceptingInstr)i).getClosureArg();
if (i instanceof CallBase && o == null) {
Expand All @@ -627,7 +625,6 @@ public void unbox(Map<Variable, TemporaryLocalVariable> unboxMap) {
Class receiverType = getOperandType(tmpState, r);
Class argType = getOperandType(tmpState, a);

// Optimistically assume that call is an ALU op
Operation unboxedOp = null;
Class unboxedType = null;
if (problem.acceptsArgTypes(m, receiverType, argType)) {
Expand Down

0 comments on commit 41e4586

Please sign in to comment.