void PhiElimination::splitCriticalEdge( IRFunction * func, BasicBlock * block) { //if (block->numOfPrecursors() <= 1) // return; auto GetInnerBlock = [func, block] (const std::string &from, const std::string &to) { BasicBlock *BB = func->createBasicBlock(from + "-" + to); Goto *go2 = IRContext::create<Goto>(block); BB->push_back(go2); BB->addSuccessor(block); go2->set_parent(BB); return BB; }; size_t size = block->numOfPrecursors(); for (auto pre = block->precursor_begin(); pre != block->precursor_end(); ++pre) { BasicBlock *PBB = *pre; // Check whether split. if (PBB->numOfSuccessors() <= 1) continue; // split it. BasicBlock *BB = GetInnerBlock( PBB->getBlockName(), block->getBlockName()); *pre = BB; PBB->successor_replace(block, BB); if (PBB->back()->is_goto()) { Goto *GT = static_cast<Goto*>(PBB->back()); GT->setTarget(BB); } else if (PBB->back()->is_branch()) { Branch *branch = static_cast<Branch*>(PBB->back()); if (branch->then() == block) branch->setThen(BB); else branch->setElse(BB); } else { assert(0 && "impossible"); } } }
BasicBlock* BasicBlock::readBasicBlock(FILE* in) { if (feof(in) || ferror(in)) return NULL; uint32_t id; uint32_t typeInt; int succ1; int succ2; if (4 == fscanf(in, "%u,%u,%i,%i", &id, &typeInt, &succ1, &succ2)) { BasicBlock* b = new BasicBlock((uint32_t)id); b->setType((task_type)typeInt); if (succ1 != -1) b->addSuccessor((uint32_t)succ1); if (succ2 != -1) b->addSuccessor((uint32_t)succ2); return b; } else { return NULL; } }