writes = new int[variableCount];
}
public void analyze(Program program) {
DefinitionExtractor defExtractor = new DefinitionExtractor();
UsageExtractor useExtractor = new UsageExtractor();
for (int i = 0; i < program.basicBlockCount(); ++i) {
BasicBlock block = program.basicBlockAt(i);
for (Instruction insn : block.getInstructions()) {
insn.acceptVisitor(defExtractor);
insn.acceptVisitor(useExtractor);
for (Variable var : defExtractor.getDefinedVariables()) {
writes[var.getIndex()]++;
}
for (Variable var : useExtractor.getUsedVariables()) {
reads[var.getIndex()]++;
}
}
for (Phi phi : block.getPhis()) {
writes[phi.getReceiver().getIndex()] += phi.getIncomings().size();