From 52937fb68506977e6b708c800b26188ed19b93b6 Mon Sep 17 00:00:00 2001 From: Ilia Mirkin Date: Sun, 28 Jun 2015 03:46:25 -0400 Subject: [PATCH] nv50/ir: keep track of how we change incoming bb order in PhiMovesPass Detaching and attaching bb's will potentially change the incoming bb order. Keep track of any such changes that happen and remap the phi node arguments while we add mov's. Signed-off-by: Ilia Mirkin --- src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp | 36 ++++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp index 898653c..b51cb3e 100644 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp @@ -360,16 +360,25 @@ RegAlloc::PhiMovesPass::visit(BasicBlock *bb) Instruction *phi, *mov; BasicBlock *pb, *pn; - std::stack stack; + typedef std::pair inbound; + std::list edges; + std::list::iterator it; - for (Graph::EdgeIterator ei = bb->cfg.incident(); !ei.end(); ei.next()) { + std::stack::iterator> stack; + + int j = 0; + for (Graph::EdgeIterator ei = bb->cfg.incident(); !ei.end(); ei.next(), ++j) { pb = BasicBlock::get(ei.getNode()); assert(pb); - if (needNewElseBlock(bb, pb)) - stack.push(pb); + edges.push_back(std::make_pair(j, pb)); + if (needNewElseBlock(bb, pb)) { + it = edges.end(); + stack.push(--it); + } } while (!stack.empty()) { - pb = stack.top(); + it = stack.top(); + pb = it->second; pn = new BasicBlock(func); stack.pop(); @@ -377,15 +386,23 @@ RegAlloc::PhiMovesPass::visit(BasicBlock *bb) pb->cfg.attach(&pn->cfg, Graph::Edge::TREE); pn->cfg.attach(&bb->cfg, Graph::Edge::FORWARD); + // Now do this same update in our inbound edge mapping. Detaching + // removes from the list, and attaching adds to the front. + j = it->first; + edges.erase(it); + edges.push_front(std::make_pair(j, pn)); + assert(pb->getExit()->op != OP_CALL); if (pb->getExit()->asFlow()->target.bb == bb) pb->getExit()->asFlow()->target.bb = pn; } // insert MOVs (phi->src(j) should stem from j-th in-BB) - int j = 0; - for (Graph::EdgeIterator ei = bb->cfg.incident(); !ei.end(); ei.next()) { + it = edges.begin(); + for (Graph::EdgeIterator ei = bb->cfg.incident(); !ei.end(); ei.next(), ++it) { pb = BasicBlock::get(ei.getNode()); + assert(it != edges.end()); + assert(it->second == pb); if (!pb->isTerminated()) pb->insertTail(new_FlowInstruction(func, OP_BRA, bb)); @@ -393,13 +410,12 @@ RegAlloc::PhiMovesPass::visit(BasicBlock *bb) LValue *tmp = new_LValue(func, phi->getDef(0)->asLValue()); mov = new_Instruction(func, OP_MOV, typeOfSize(tmp->reg.size)); - mov->setSrc(0, phi->getSrc(j)); + mov->setSrc(0, phi->getSrc(it->first)); mov->setDef(0, tmp); - phi->setSrc(j, tmp); + phi->setSrc(it->first, tmp); pb->insertBefore(pb->getExit(), mov); } - ++j; } return true; -- 2.3.6