/** * Update the value graph to account for a given InlineGuard instruction. * * <p><b>PRECONDITION:</b> <code> InlineGuard.conforms(s); </code> * * @param s the instruction in question */ private void processInlineGuard(Instruction s) { ValueGraphVertex v = new ValueGraphVertex(s); graph.addGraphNode(v); nameMap.put(s, v); if (s.operator() == IG_PATCH_POINT) { // the 'goal' is irrelevant for patch_point guards. v.setLabel(s.operator(), 1); link(v, findOrCreateVertex(bypassMoves(InlineGuard.getValue(s))), 0); } else { v.setLabel(s.operator(), 2); link(v, findOrCreateVertex(bypassMoves(InlineGuard.getValue(s))), 0); link(v, findOrCreateVertex(InlineGuard.getGoal(s)), 1); } }
/** * Update the value graph to account for a given NEWARRAY instruction. * * <p><b>PRECONDITION:</b> <code> NewArray.conforms(s); </code> For a newarray instruction, we * always create a new vertex. * * @param s the instruction in question */ private void processNewArray(Instruction s) { RegisterOperand result = NewArray.getResult(s); ValueGraphVertex v = findOrCreateVertex(result.getRegister()); // set the label for a NEW instruction to be the instruction itself // so that no two NEW results get the same value number v.setLabel(s, 0); }
/** * Update the value graph to account for an IR_PROLOGUE instruction * * <p><b>PRECONDITION:</b> <code> Prologue.conforms(s); </code> * * @param s the instruction in question */ private void processPrologue(Instruction s) { int numArgs = 0; for (Enumeration<Operand> e = s.getDefs(); e.hasMoreElements(); numArgs++) { Register formal = ((RegisterOperand) e.nextElement()).getRegister(); ValueGraphVertex v = findOrCreateVertex(formal); v.setLabel(new ValueGraphParamLabel(numArgs), 0); } }
/** * Update the value graph to account for a given IfCmp instruction. * * <p><b>PRECONDITION:</b> <code> IfCmp.conforms(s); </code> * * @param s the instruction in question */ private void processIfCmp(Instruction s) { ValueGraphVertex v = new ValueGraphVertex(s); graph.addGraphNode(v); nameMap.put(s, v); v.setLabel(s.operator(), 3); link(v, findOrCreateVertex(bypassMoves(IfCmp.getVal1(s))), 0); link(v, findOrCreateVertex(bypassMoves(IfCmp.getVal2(s))), 1); link(v, findOrCreateVertex(IfCmp.getCond(s)), 2); }
/** * Find or create an ValueGraphVertex corresponding to a given register * * @param r the register * @return a value graph vertex corresponding to this variable */ private ValueGraphVertex findOrCreateVertex(Register r) { ValueGraphVertex v = getVertex(r); if (v == null) { v = new ValueGraphVertex(r); v.setLabel(r, 0); graph.addGraphNode(v); nameMap.put(r, v); } return v; }
/** * Find or create an ValueGraphVertex corresponding to a given method operand * * @param op the operand in question * @return a value graph vertex corresponding to this type */ private ValueGraphVertex findOrCreateVertex(ConditionOperand op) { Object name = op.value; // kludge. ValueGraphVertex v = getVertex(name); if (v == null) { v = new ValueGraphVertex(op); v.setLabel(op, 0); graph.addGraphNode(v); nameMap.put(name, v); } return v; }
/** * Find or create an ValueGraphVertex corresponding to a given type operand * * @param op the operand in question * @return a value graph vertex corresponding to this type */ private ValueGraphVertex findOrCreateVertex(TypeOperand op) { Object name = op.getTypeRef(); ValueGraphVertex v = getVertex(name); if (v == null) { v = new ValueGraphVertex(op); v.setLabel(op, 0); graph.addGraphNode(v); nameMap.put(name, v); } return v; }
/** * Update the value graph to account for a given NullCheck instruction. * * <p><b>PRECONDITION:</b> <code> ZeroCheck.conforms(s); </code> * * @param s the instruction in question */ private void processZeroCheck(Instruction s) { // label the vertex corresponding to the result with the operator RegisterOperand result = ZeroCheck.getGuardResult(s); ValueGraphVertex v = findOrCreateVertex(result.getRegister()); v.setLabel(s.operator(), 1); // link node v to the operand it uses Operand val = ZeroCheck.getValue(s); // bypass Move instructions val = bypassMoves(val); link(v, findOrCreateVertex(val), 0); }
/** * Update the value graph to account for a given GuardedBinary instruction. * * <p><b>PRECONDITION:</b> <code> GuardedBinary.conforms(s); </code> Careful: we define two * Guarded Binaries to be equivalent regardless of whether the guards are equivalent! * * @param s the instruction in question */ private void processGuardedBinary(Instruction s) { // label the vertex corresponding to the result with the operator RegisterOperand result = GuardedBinary.getResult(s); ValueGraphVertex v = findOrCreateVertex(result.getRegister()); v.setLabel(s.operator(), 2); // link node v to the two operands it uses // first link the first val Operand val = GuardedBinary.getVal1(s); val = bypassMoves(val); link(v, findOrCreateVertex(val), 0); Operand val2 = GuardedBinary.getVal2(s); val2 = bypassMoves(val2); link(v, findOrCreateVertex(val2), 1); }
/** * Update the value graph to account for a given Phi instruction. * * <p><b>PRECONDITION:</b> <code> Phi.conforms(s); </code> * * @param s the instruction in question */ private void processPhi(Instruction s) { // the label for a PHI instruction is the basic block // in which it appears Register result = Phi.getResult(s).asRegister().getRegister(); ValueGraphVertex v = findOrCreateVertex(result); BasicBlock bb = s.getBasicBlock(); v.setLabel(bb, bb.getNumberOfIn()); // link node v to all operands it uses for (int i = 0; i < Phi.getNumberOfValues(s); i++) { Operand val = Phi.getValue(s, i); val = bypassMoves(val); ValueGraphVertex target = findOrCreateVertex(val); link(v, target, i); } }
/** * Find or create an ValueGraphVertex corresponding to a given method operand * * @param op the operand in question * @return a value graph vertex corresponding to this type */ private ValueGraphVertex findOrCreateVertex(MethodOperand op) { Object name; if (op.hasTarget()) { name = op.getTarget(); } else { name = op.getMemberRef(); } ValueGraphVertex v = getVertex(name); if (v == null) { v = new ValueGraphVertex(op); v.setLabel(op, 0); graph.addGraphNode(v); nameMap.put(name, v); } return v; }
/** * Find or create an ValueGraphVertex corresponding to a given constant operand * * @param op the constant operand * @return a value graph vertex corresponding to this variable */ private ValueGraphVertex findOrCreateVertex(ConstantOperand op) { Object name; if (op.isAddressConstant()) { name = (VM.BuildFor32Addr) ? op.asAddressConstant().value.toInt() : op.asAddressConstant().value.toLong(); } else if (op.isIntConstant()) { name = op.asIntConstant().value; } else if (op.isFloatConstant()) { name = op.asFloatConstant().value; } else if (op.isLongConstant()) { name = op.asLongConstant().value; } else if (op.isDoubleConstant()) { name = op.asDoubleConstant().value; } else if (op instanceof ObjectConstantOperand) { name = op.asObjectConstant().value; } else if (op instanceof TIBConstantOperand) { name = op.asTIBConstant().value; } else if (op.isNullConstant()) { name = op; } else if (op instanceof TrueGuardOperand) { name = op; } else if (op instanceof UnreachableOperand) { name = op; } else { throw new OptimizingCompilerException( "ValueGraph.findOrCreateVertex: unexpected constant operand: " + op); } ValueGraphVertex v = getVertex(name); if (v == null) { v = new ValueGraphVertex(op); v.setLabel(op, 0); graph.addGraphNode(v); nameMap.put(name, v); } return v; }