use of org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand in project JikesRVM by JikesRVM.
the class NormalizeConstants method perform.
/**
* Only thing we do for IA32 is to restrict the usage of
* String, Float, and Double constants. The rules are prepared
* to deal with everything else.
*
* @param ir IR to normalize
*/
public static void perform(IR ir) {
for (Instruction s = ir.firstInstructionInCodeOrder(); s != null; s = s.nextInstructionInCodeOrder()) {
// Get 'large' constants into a form the the BURS rules are
// prepared to deal with.
// Constants can't appear as defs, so only scan the uses.
//
int numUses = s.getNumberOfUses();
if (numUses > 0) {
int numDefs = s.getNumberOfDefs();
for (int idx = numDefs; idx < numUses + numDefs; idx++) {
Operand use = s.getOperand(idx);
if (use != null) {
if (use instanceof ObjectConstantOperand) {
ObjectConstantOperand oc = (ObjectConstantOperand) use;
if (oc.isMovableObjectConstant()) {
RegisterOperand rop = ir.regpool.makeTemp(use.getType());
Operand jtoc = ir.regpool.makeJTOCOp();
Offset offset = oc.offset;
if (offset.isZero()) {
if (use instanceof StringConstantOperand) {
throw new OptimizingCompilerException("String constant w/o valid JTOC offset");
} else if (use instanceof ClassConstantOperand) {
throw new OptimizingCompilerException("Class constant w/o valid JTOC offset");
}
offset = Offset.fromIntSignExtend(Statics.findOrCreateObjectLiteral(oc.value));
}
LocationOperand loc = new LocationOperand(offset);
s.insertBefore(Load.create(IA32_REF_LOAD, rop, jtoc, wordOperandForReference(offset.toWord()), loc));
s.putOperand(idx, rop.copyD2U());
} else {
// Ensure object is in JTOC to keep it alive
Statics.findOrCreateObjectLiteral(oc.value);
s.putOperand(idx, wordOperandForReference(Magic.objectAsAddress(oc.value).toWord()));
}
} else if (use instanceof DoubleConstantOperand) {
RegisterOperand rop = ir.regpool.makeTemp(TypeReference.Double);
Operand jtoc = ir.regpool.makeJTOCOp();
DoubleConstantOperand dc = (DoubleConstantOperand) use.copy();
if (dc.offset.isZero()) {
dc.offset = Offset.fromIntSignExtend(Statics.findOrCreateLongSizeLiteral(Double.doubleToLongBits(dc.value)));
}
s.insertBefore(Binary.create(MATERIALIZE_FP_CONSTANT, rop, jtoc, dc));
s.putOperand(idx, rop.copyD2U());
} else if (use instanceof FloatConstantOperand) {
RegisterOperand rop = ir.regpool.makeTemp(TypeReference.Float);
Operand jtoc = ir.regpool.makeJTOCOp();
FloatConstantOperand fc = (FloatConstantOperand) use.copy();
if (fc.offset.isZero()) {
fc.offset = Offset.fromIntSignExtend(Statics.findOrCreateIntSizeLiteral(Float.floatToIntBits(fc.value)));
}
s.insertBefore(Binary.create(MATERIALIZE_FP_CONSTANT, rop, jtoc, fc));
s.putOperand(idx, rop.copyD2U());
} else if (use instanceof NullConstantOperand) {
s.putOperand(idx, wordOperandForReference(Word.zero()));
} else if (use instanceof AddressConstantOperand) {
s.putOperand(idx, wordOperandForReference(((AddressConstantOperand) use).value.toWord()));
} else if (use instanceof TIBConstantOperand) {
RegisterOperand rop = ir.regpool.makeTemp(TypeReference.TIB);
Operand jtoc = ir.regpool.makeJTOCOp();
Offset offset = ((TIBConstantOperand) use).value.getTibOffset();
LocationOperand loc = new LocationOperand(offset);
s.insertBefore(Load.create(IA32_REF_LOAD, rop, jtoc, wordOperandForReference(offset.toWord()), loc));
s.putOperand(idx, rop.copyD2U());
} else if (use instanceof CodeConstantOperand) {
RegisterOperand rop = ir.regpool.makeTemp(TypeReference.CodeArray);
Operand jtoc = ir.regpool.makeJTOCOp();
Offset offset = ((CodeConstantOperand) use).value.findOrCreateJtocOffset();
LocationOperand loc = new LocationOperand(offset);
s.insertBefore(Load.create(IA32_REF_LOAD, rop, jtoc, wordOperandForReference(offset.toWord()), loc));
s.putOperand(idx, rop.copyD2U());
}
}
}
}
}
}
use of org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand in project JikesRVM by JikesRVM.
the class ConvertToLowLevelIR method getTIB.
static Operand getTIB(Instruction s, IR ir, Operand obj, Operand guard) {
if (obj.isObjectConstant()) {
// NB Constant types must already be resolved
try {
RVMType type = obj.getType().resolve();
return new TIBConstantOperand(type);
} catch (NoClassDefFoundError e) {
if (VM.runningVM)
throw e;
// Class not found during bootstrap due to chasing a class
// only valid in the bootstrap JVM
}
}
RegisterOperand res = ir.regpool.makeTemp(TypeReference.TIB);
Instruction s2 = GuardedUnary.create(GET_OBJ_TIB, res, obj, guard);
s.insertBefore(s2);
return res.copyD2U();
}
Aggregations