for (OPT_BasicBlockEnumeration allBB = ir.getBasicBlocks(); allBB.hasMoreElements(); ) { OPT_BasicBlock bb = allBB.next();
for (OPT_BasicBlock bb = ir.firstBasicBlockInCodeOrder(); bb != null; bb = bb.nextBasicBlockInCodeOrder()) {
  final public void perform (OPT_IR ir) {    OPT_RegisterOperand tempReg = ir.regpool.makeTemp(VM_Type.IntType);    // For each basic block    for (OPT_BasicBlockEnumeration allBB = ir.getBasicBlocks(); 	 allBB.hasMoreElements(); ) {      OPT_BasicBlock bb = allBB.next();      boolean inPrologue = (bb == ir.cfg.entry());      // For each instruction      for (OPT_InstructionEnumeration ie	     = bb.forwardInstrEnumerator();	   ie.hasMoreElements();) {	OPT_Instruction i = ie.next();			// If it's an instrumentation operation, expand it	if (i.operator() == YIELDPOINT_PROLOGUE ||	    i.operator() == YIELDPOINT_EPILOGUE ||	    i.operator() == YIELDPOINT_BACKEDGE) {	  OPT_Instruction instBeforeYP = i.prevInstructionInCodeOrder();	  OPT_BasicBlock beforeYP = bb;	  // Split the basic block into three blocks (beforeYP, ypBB,	  // and afterYP) so the yieldpoint is isolated and can be	  // branched around.	  OPT_BasicBlock ypBB = bb.splitNodeWithLinksAt(instBeforeYP,ir); 	  ypBB.recomputeNormalOut(ir);	  bb.recomputeNormalOut(ir);	  // Split block to separate the 	  OPT_BasicBlock afterYP = ypBB.splitNodeWithLinksAt(i,ir);	  afterYP.recomputeNormalOut(ir);	  ypBB.recomputeNormalOut(ir);	  // call to threadswitch is cold and can go to bottom	  ypBB.setInfrequent(); 	  // Replace the yieldpoint instruction with a call to threadswitch 	  VM_Method m = null;	  if (inPrologue)	    m = OPT_Entrypoints.threadSwitchFromPrologueMethod;	  else	    m = OPT_Entrypoints.threadSwitchFromBackedgeMethod;	  	  OPT_Instruction c = 	    Call.create0(CALL, null, null, OPT_MethodOperand.STATIC(m));	  c.position = ir.gc.inlineSequence;	  c.bcIndex = INSTRUMENTATION_BCI;	  // Insert load after call to threadswitch	  OPT_Instruction load = 	    Load.create(INT_LOAD, tempReg.copyRO(), 			ir.regpool.makeJTOCOp(ir,i), 			OPT_IRTools.I(VM_Entrypoints.deterministicThreadSwitchCountOffset),			new OPT_LocationOperand(VM_Entrypoints.						deterministicThreadSwitchCountOffset));	  // Insert the call followed by the load	  i.insertBefore(c);	  c.insertAfter(load);	  // Remove yieldpoint	  i.remove();	  // We're in LIR so lower the new call	  OPT_ConvertToLowLevelIR.call(c,ir);	  // pfs: need insert before instruction for Intel.	  OPT_Instruction dummy = new OPT_Instruction(OPT_Operator.OperatorArray[1], 4);	  beforeYP.appendInstruction(dummy);	  // Create the initial load (for the conditional check)	  load = 	    Load.create(INT_LOAD, tempReg.copyRO(), 			ir.regpool.makeJTOCOp(ir,dummy), 			OPT_IRTools.I(VM_Entrypoints.deterministicThreadSwitchCountOffset),			new OPT_LocationOperand(VM_Entrypoints.						deterministicThreadSwitchCountOffset));	  	  	  //	  beforeYP.appendInstruction(load);	  dummy.insertBefore(load);	  dummy.remove();	  // make the branch jump to the basic block afterYP	  OPT_ConditionOperand cond = OPT_ConditionOperand.GREATER();	  OPT_BranchOperand target = afterYP.makeJumpTarget();	  OPT_RegisterOperand guard = ir.regpool.makeTempValidation();	  beforeYP.appendInstruction(IfCmp.create(INT_IFCMP, 						  guard,						  tempReg.copyRO(),						  new OPT_IntConstantOperand(0),						  cond,						  target,						  new OPT_BranchProfileOperand(1.0)));	  beforeYP.recomputeNormalOut(ir);	  // Insert the increment and store in block afterYP	  // Prepend store	  // pfs: cludge to get instruction to insert before.	  afterYP.prependInstruction(dummy);	  OPT_Instruction store = 	    Store.create(INT_STORE, 			 tempReg.copyRO(),			 ir.regpool.makeJTOCOp(ir,dummy), 			 OPT_IRTools.I(VM_Entrypoints.				       deterministicThreadSwitchCountOffset),			 new OPT_LocationOperand(VM_Entrypoints.						 deterministicThreadSwitchCountOffset));	  //	  afterYP.prependInstruction(store);	  dummy.insertBefore(store);	  dummy.remove();	  // prependDecrement(afterYP,ir);	  OPT_RegisterOperand use = tempReg.copyD2U();	  OPT_RegisterOperand def = use.copyU2D();	  OPT_Instruction inc = Binary.create(INT_ADD,					      def,use, 					      OPT_IRTools.I(-1));	  afterYP.prependInstruction(inc);    	  // Matt, don't you need a recomputeNormalOut?	  afterYP.recomputeNormalOut(ir);	}      }    }  }