private void addEdge(OPT_BasicBlock target, float weight) { if (max == targets.length) { OPT_BasicBlock[] tmp = new OPT_BasicBlock[targets.length << 1]; for (int i=0; i<targets.length; i++) { tmp[i] = targets[i]; } targets = tmp; float [] tmp2 = new float[weights.length << 1]; for (int i=0; i<weights.length; i++) { tmp2[i] = weights[i]; } weights = tmp2; }
  OPT_WeightedBranchTargets(OPT_BasicBlock bb) {    targets = new OPT_BasicBlock[3];    weights = new float[3];    cur = 0;    max = 0;    float prob = 1f;    for (OPT_InstructionEnumeration ie = bb.enumerateBranchInstructions();	 ie.hasMoreElements();) {      OPT_Instruction s = ie.next();      if (IfCmp.conforms(s)) {	OPT_BasicBlock target = IfCmp.getTarget(s).target.getBasicBlock();	OPT_BranchProfileOperand prof = IfCmp.getBranchProfile(s);	float taken = prob * prof.takenProbability;	prob = prob * (1f - prof.takenProbability);	addEdge(target, taken);      } else if (Goto.conforms(s)) {	OPT_BasicBlock target = Goto.getTarget(s).target.getBasicBlock();      	addEdge(target, prob);      } else if (InlineGuard.conforms(s)) {	OPT_BasicBlock target = InlineGuard.getTarget(s).target.getBasicBlock();	OPT_BranchProfileOperand prof = InlineGuard.getBranchProfile(s);	float taken = prob * prof.takenProbability;	prob = prob * (1f - prof.takenProbability);	addEdge(target, taken);      } else if (IfCmp2.conforms(s)) {	OPT_BasicBlock target = IfCmp2.getTarget1(s).target.getBasicBlock();	OPT_BranchProfileOperand prof = IfCmp2.getBranchProfile1(s);	float taken = prob * prof.takenProbability;	prob = prob * (1f - prof.takenProbability);	addEdge(target, taken);	target = IfCmp2.getTarget2(s).target.getBasicBlock();	prof = IfCmp2.getBranchProfile2(s);	taken = prob * prof.takenProbability;	prob = prob * (1f - prof.takenProbability);	addEdge(target, taken);      } else if (TableSwitch.conforms(s)) {	int lowLimit = TableSwitch.getLow(s).value;	int highLimit = TableSwitch.getHigh(s).value;	int number = highLimit - lowLimit + 1;	float total = 0f;	for (int i=0; i<number; i++) {	  OPT_BasicBlock target = TableSwitch.getTarget(s, i).target.getBasicBlock();	  OPT_BranchProfileOperand prof = TableSwitch.getBranchProfile(s, i);	  float taken = prob * prof.takenProbability;	  total += prof.takenProbability;	  addEdge(target, taken);	}	OPT_BasicBlock target = TableSwitch.getDefault(s).target.getBasicBlock();	OPT_BranchProfileOperand prof = TableSwitch.getDefaultBranchProfile(s);	float taken = prob * prof.takenProbability;	total += prof.takenProbability;	if (VM.VerifyAssertions) VM.assert(epsilon(total, 1f), "total = "+total);	addEdge(target, taken);      } else if (LowTableSwitch.conforms(s)) {	int number = LowTableSwitch.getNumberOfTargets(s);	float total = 0f;	for (int i=0; i<number; i++) {	  OPT_BasicBlock target = LowTableSwitch.getTarget(s, i).target.getBasicBlock();	  OPT_BranchProfileOperand prof = LowTableSwitch.getBranchProfile(s, i);	  float taken = prob * prof.takenProbability;	  total += prof.takenProbability;	  addEdge(target, taken);	}	if (VM.VerifyAssertions) VM.assert(epsilon(total, 1f), "total = "+total);      } else if (LookupSwitch.conforms(s)) {	int number = LookupSwitch.getNumberOfTargets(s);	float total = 0f;	for (int i=0; i<number; i++) {	  OPT_BasicBlock target = LookupSwitch.getTarget(s, i).target.getBasicBlock();	  OPT_BranchProfileOperand prof = LookupSwitch.getBranchProfile(s, i);	  float taken = prob * prof.takenProbability;	  total += prof.takenProbability;	  addEdge(target, taken);	}	OPT_BasicBlock target = LookupSwitch.getDefault(s).target.getBasicBlock();	OPT_BranchProfileOperand prof = LookupSwitch.getDefaultBranchProfile(s);	float taken = prob * prof.takenProbability;	total += prof.takenProbability;	if (VM.VerifyAssertions) VM.assert(epsilon(total, 1f), "total = "+total);	addEdge(target, taken);      } else {	throw new OPT_OptimizingCompilerException("TODO "+s+"\n");      }    }    OPT_BasicBlock ft = bb.getFallThroughBlock();    if (ft != null) addEdge(ft, prob);  }  private void addEdge(OPT_BasicBlock target, float weight) {    if (max == targets.length) {      OPT_BasicBlock[] tmp = new OPT_BasicBlock[targets.length << 1];      for (int i=0; i<targets.length; i++) {	tmp[i] = targets[i];      }      targets = tmp;      float [] tmp2 = new float[weights.length << 1];      for (int i=0; i<weights.length; i++) {	tmp2[i] = weights[i];      }      weights = tmp2;    }