Example #1
0
 private boolean isExceptionHandler(Incoming incoming) {
   return incoming
       .getSource()
       .getTryCatchJoints()
       .stream()
       .anyMatch(joint -> joint.getReceiver() == incoming.getValue());
 }
Example #2
0
 private void insertCopy(Incoming incoming, Map<BasicBlock, BasicBlock> blockMap) {
   final Phi phi = incoming.getPhi();
   Program program = phi.getBasicBlock().getProgram();
   AssignInstruction copyInstruction = new AssignInstruction();
   Variable firstCopy = program.createVariable();
   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)) {
     final BasicBlock copyBlock = program.createBasicBlock();
     JumpInstruction jumpInstruction = new JumpInstruction();
     jumpInstruction.setTarget(phi.getBasicBlock());
     copyBlock.getInstructions().add(jumpInstruction);
     incoming
         .getSource()
         .getLastInstruction()
         .acceptVisitor(
             new BasicBlockMapper(
                 block -> block == phi.getBasicBlock().getIndex() ? copyBlock.getIndex() : block));
     blockMap.put(source, copyBlock);
     incoming.setSource(copyBlock);
     source = copyBlock;
   }
   source.getInstructions().add(source.getInstructions().size() - 1, copyInstruction);
   incoming.setValue(copyInstruction.getReceiver());
 }
Example #3
0
 private DisjointSet buildPhiCongruenceClasses(Program program) {
   DisjointSet classes = new DisjointSet();
   for (int i = 0; i < program.variableCount(); ++i) {
     classes.create();
   }
   for (int i = 0; i < program.basicBlockCount(); ++i) {
     BasicBlock block = program.basicBlockAt(i);
     for (Phi phi : block.getPhis()) {
       for (Incoming incoming : phi.getIncomings()) {
         classes.union(phi.getReceiver().getIndex(), incoming.getValue().getIndex());
       }
     }
     for (TryCatchJoint joint : block.getTryCatchJoints()) {
       for (Variable sourceVar : joint.getSourceVariables()) {
         classes.union(sourceVar.getIndex(), joint.getReceiver().getIndex());
       }
     }
   }
   return classes;
 }