void OSR::replace(SsaOpnd* opnd, SsaOpnd* iv, SsaOpnd* rc) { Inst* inst = opnd->getInst(); SsaOpnd* dstInst = reduce(inst->getDst()->getType(), inst->getOpcode(), inst->getOperation(), iv, rc); Inst* copyInst = irManager.getInstFactory().makeCopy(opnd, dstInst); copyInst->insertBefore(inst); inst->unlink(); writeLeadingOperand(opnd, getLeadingOperand(iv)); }
Node * JavaFlowGraphBuilder::edgesForBlock(Node* block) { // // find if this block has any region that could catch the exception // Node *dispatch = NULL; ExceptionInfo *exceptionInfo = (CatchBlock*)((LabelInst*)block->getFirstInst())->getState(); if (exceptionInfo != NULL) { dispatch = exceptionInfo->getLabelInst()->getNode(); }else{ dispatch = fg->getUnwindNode(); } assert(dispatch->isDispatchNode()); // // split the block so that // each potentially-exceptional instruction ends a block // Inst* first = (Inst*)block->getFirstInst(); Inst* last = (Inst*)block->getLastInst(); Inst* lastExceptionalInstSeen = NULL; for (Inst* inst = first->getNextInst(); inst != NULL; inst = inst->getNextInst()) { if (lastExceptionalInstSeen != NULL) { // start a new basic block LabelInst* label = irBuilder.getInstFactory()->makeLabel(); Node *newblock = createBlockNodeAfter(block, label); uint16 bcOffset = ILLEGAL_BC_MAPPING_VALUE; for (Inst *ins = lastExceptionalInstSeen->getNextInst(), *nextIns = NULL; ins!=NULL; ins = nextIns) { nextIns = ins->getNextInst(); ins->unlink(); newblock->appendInst(ins); if (bcOffset == ILLEGAL_BC_MAPPING_VALUE) { bcOffset = ins->getBCOffset(); } } label->setBCOffset(bcOffset); // now fix up the CFG, duplicating edges if (!lastExceptionalInstSeen->isThrow()) fg->addEdge(block,newblock); // // add an edge to handler entry node // assert(!block->findTargetEdge(dispatch)); fg->addEdge(block,dispatch); block = newblock; lastExceptionalInstSeen = NULL; } if (inst->getOperation().canThrow()) { lastExceptionalInstSeen = inst; } } // // examine the last instruction and create appropriate CFG edges // switch(last->getOpcode()) { case Op_Jump: { fg->addEdge(block,((BranchInst*)last)->getTargetLabel()->getNode()); last->unlink(); } break; case Op_Branch: case Op_JSR: addEdge(block, ((BranchInst*)last)->getTargetLabel()->getNode()); edgeForFallthrough(block); break; case Op_Throw: case Op_ThrowSystemException: case Op_ThrowLinkingException: // throw/rethrow creates an edge to a handler that catches the exception assert(dispatch != NULL); assert(lastExceptionalInstSeen == last); break; case Op_Return: addEdge(block, fg->getReturnNode()); break; case Op_Ret: break; // do not do anything case Op_Switch: { SwitchInst *sw = (SwitchInst*)last; U_32 num = sw->getNumTargets(); for (U_32 i = 0; i < num; i++) { Node* target = sw->getTarget(i)->getNode(); // two switch values may go to the same block if (!block->findTargetEdge(target)) { fg->addEdge(block,target); } } Node* target = sw->getDefaultTarget()->getNode(); if (!block->findTargetEdge(target)) { fg->addEdge(block,target); } } break; default:; if (block != fg->getReturnNode()) { // a fallthrough edge is needed // if the basic block does not have any outgoing edge, add one fall through edge if (block->getOutEdges().empty()) edgeForFallthrough(block); } } // // add an edge to handler entry node // if (lastExceptionalInstSeen != NULL) addEdge(block,dispatch); return block; }