public static void makeUniqueLabels(Program program) { Set<String> occupiedLabels = new HashSet<>(); for (int i = 0; i < program.variableCount(); ++i) { Variable var = program.variableAt(i); if (var.getLabel() == null) { continue; } String suggestedName = var.getLabel(); if (!occupiedLabels.add(suggestedName)) { int suffix = 1; String base = suggestedName + "_"; do { suggestedName = base + suffix++; } while (!occupiedLabels.add(suggestedName)); } var.setLabel(suggestedName); } }
private Variable introduce(Variable var) { if (!usedDefinitions[var.getIndex()]) { usedDefinitions[var.getIndex()] = true; } else { Variable old = var; var = program.createVariable(); var.setDebugName(old.getDebugName()); var.setLabel(old.getLabel()); } return var; }
@Override public void visit(NullConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); NullConstantInstruction copy = new NullConstantInstruction(); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(IntegerConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); IntegerConstantInstruction copy = new IntegerConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(DoubleConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); DoubleConstantInstruction copy = new DoubleConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(LongConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); LongConstantInstruction copy = new LongConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(ClassConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); ClassConstantInstruction copy = new ClassConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(FloatConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); FloatConstantInstruction copy = new FloatConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(StringConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); StringConstantInstruction copy = new StringConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; } }
@Override public void visit(AssignInstruction insn) { if (namesPreserved) { if (insn.getReceiver().getDebugName() != null && insn.getAssignee().getDebugName() != null) { if (!insn.getAssignee().getDebugName().equals(insn.getReceiver().getDebugName())) { return; } } } if (insn.getReceiver().getDebugName() != null) { insn.getAssignee().setDebugName(insn.getReceiver().getDebugName()); } if (insn.getReceiver().getLabel() != null) { insn.getAssignee().setLabel(insn.getReceiver().getLabel()); } map[insn.getReceiver().getIndex()] = map[insn.getAssignee().getIndex()]; eliminate = true; }
private Program createStubCopy(Program program) { Program copy = new Program(); for (int i = 0; i < program.basicBlockCount(); ++i) { copy.createBasicBlock(); } for (int i = 0; i < program.variableCount(); ++i) { Variable var = program.variableAt(i); copy.createVariable(); Variable varCopy = copy.variableAt(i); varCopy.setRegister(var.getRegister()); varCopy.setDebugName(var.getDebugName()); varCopy.setLabel(var.getLabel()); } return copy; }
preheaderPhi = new Phi(); preheaderPhi.setReceiver(program.createVariable()); preheaderPhi.getReceiver().setLabel(phi.getReceiver().getLabel()); preheaderPhi.getReceiver().setDebugName(phi.getReceiver().getDebugName()); preheader.getPhis().add(preheaderPhi);
variableToSourceMap.add(sigma.getValue().getIndex()); outgoingVar.setDebugName(sigma.getValue().getDebugName()); outgoingVar.setLabel(sigma.getValue().getLabel()); Outgoing outgoing = new Outgoing(outgoingVar, target); sigma.getOutgoings().add(outgoing);
void processMemberMethods(ClassHolder cls) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { if (method.hasModifier(ElementModifier.STATIC)) { continue; } if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) { ValueType[] staticSignature = getStaticSignature(method.getReference()); MethodHolder callerMethod = new MethodHolder(new MethodDescriptor(method.getName() + "$static", staticSignature)); callerMethod.getModifiers().add(ElementModifier.STATIC); Program program = ProgramUtils.copy(method.getProgram()); program.createVariable(); InstructionVariableMapper variableMapper = new InstructionVariableMapper(var -> program.variableAt(var.getIndex() + 1)); for (int i = program.variableCount() - 1; i > 0; --i) { program.variableAt(i).setDebugName(program.variableAt(i - 1).getDebugName()); program.variableAt(i).setLabel(program.variableAt(i - 1).getLabel()); } for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); variableMapper.apply(block); } callerMethod.setProgram(program); ModelUtils.copyAnnotations(method.getAnnotations(), callerMethod.getAnnotations()); cls.addMethod(callerMethod); } } }
Variable var = program.createVariable(); var.setDebugName(phi.getReceiver().getDebugName()); var.setLabel(phi.getReceiver().getLabel()); mapVariable(phi.getReceiver().getIndex(), var); phisByReceiver.put(var.getIndex(), phi);
private void insertCopy(Incoming incoming, Map<BasicBlock, BasicBlock> blockMap) { Phi phi = incoming.getPhi(); Program program = phi.getBasicBlock().getProgram(); AssignInstruction copyInstruction = new AssignInstruction(); Variable firstCopy = program.createVariable(); firstCopy.setLabel(phi.getReceiver().getLabel()); firstCopy.setDebugName(phi.getReceiver().getDebugName()); copyInstruction.setReceiver(firstCopy); copyInstruction.setAssignee(incoming.getValue()); BasicBlock source = blockMap.get(incoming.getSource()); if (source == null) { source = incoming.getSource(); } else { incoming.setSource(source); } if (!(incoming.getSource().getLastInstruction() instanceof JumpInstruction)) { BasicBlock copyBlock = program.createBasicBlock(); JumpInstruction jumpInstruction = new JumpInstruction(); jumpInstruction.setLocation(incoming.getSource().getLastInstruction().getLocation()); jumpInstruction.setTarget(phi.getBasicBlock()); copyBlock.add(jumpInstruction); incoming.getSource().getLastInstruction().acceptVisitor(new BasicBlockMapper((int block) -> block == phi.getBasicBlock().getIndex() ? copyBlock.getIndex() : block)); blockMap.put(source, copyBlock); incoming.setSource(copyBlock); source = copyBlock; } source.getLastInstruction().insertPrevious(copyInstruction); incoming.setValue(copyInstruction.getReceiver()); }
private Variable introduce(Variable var) { if (!usedDefinitions[var.getIndex()]) { usedDefinitions[var.getIndex()] = true; } else { Variable old = var; var = program.createVariable(); var.setDebugName(old.getDebugName()); var.setLabel(old.getLabel()); } return var; }
@Override public void visit(NullConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); NullConstantInstruction copy = new NullConstantInstruction(); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(DoubleConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); DoubleConstantInstruction copy = new DoubleConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }