/** Find non-locals variables. Algorithm from Briggs, Cooper, Harvey and Simpson */
  public BitSet findNonLocals() {
    BitSet nonLocals = new BitSet(nbVar);
    BitSet killed = new BitSet(nbVar);
    BitSet emptySet = new BitSet(nbVar);
    for (BasicBlock bb = firstBB; bb != null; bb = bb.getNext()) {
      // clear killed set
      killed.and(emptySet);

      Iterator insts = bb.getInstructions();
      while (insts.hasNext()) {
        QInst inst = (QInst) insts.next();
        QOperandBox[] ops = inst.getUses();
        for (int i = 0; i < ops.length; ++i) {
          QOperand op = ops[i].getOperand();
          if (op instanceof QVar) {
            int r = ((QVar) op).getRegister();
            if (!killed.get(r)) {
              nonLocals.set(r);
            }
          }
        }
        if (inst.defVar()) {
          QOperand op = inst.getDefined().getOperand();
          if (op instanceof QVar) {
            int r = ((QVar) op).getRegister();
            killed.set(r);
          }
        }
      }
    }
    return nonLocals;
  }
 private void transformBasicBlock(BasicBlock block) {
   List<Instruction> instructions = block.getInstructions();
   for (int i = 0; i < instructions.size(); ++i) {
     Instruction insn = instructions.get(i);
     if (insn instanceof InvokeInstruction) {
       InvokeInstruction invoke = (InvokeInstruction) insn;
       List<Instruction> replacement = transformInvoke(invoke);
       if (replacement != null) {
         instructions.set(i, new EmptyInstruction());
         instructions.addAll(i, replacement);
         i += replacement.size();
       }
     }
   }
 }