From c04d6d95e0efb8eea4d788d8d7b629209a3afaea Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Wed, 28 Mar 2012 21:30:59 +0200 Subject: [PATCH] nv50/ir: add function for splitting a BasicBlock Fixes to initial implementation by Francisco Jerez. --- src/gallium/drivers/nv50/codegen/nv50_ir.h | 6 +++ .../drivers/nv50/codegen/nv50_ir_bb.cpp | 54 +++++++++++++++++++ .../drivers/nv50/codegen/nv50_ir_graph.h | 27 ++++++---- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir.h b/src/gallium/drivers/nv50/codegen/nv50_ir.h index cf7bd3c0d05..04ea5e6d5a9 100644 --- a/src/gallium/drivers/nv50/codegen/nv50_ir.h +++ b/src/gallium/drivers/nv50/codegen/nv50_ir.h @@ -882,6 +882,10 @@ public: BasicBlock *idom() const; + // NOTE: currently does not rebuild the dominator tree + BasicBlock *splitBefore(Instruction *, bool attach = true); + BasicBlock *splitAfter(Instruction *, bool attach = true); + DLList& getDF() { return df; } DLList::Iterator iterDF() { return df.iterator(); } @@ -914,6 +918,8 @@ private: private: Function *func; Program *program; + + void splitCommon(Instruction *, BasicBlock *, bool attach); }; class Function diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir_bb.cpp b/src/gallium/drivers/nv50/codegen/nv50_ir_bb.cpp index c1c82788756..e766c62f47f 100644 --- a/src/gallium/drivers/nv50/codegen/nv50_ir_bb.cpp +++ b/src/gallium/drivers/nv50/codegen/nv50_ir_bb.cpp @@ -258,6 +258,60 @@ void BasicBlock::permuteAdjacent(Instruction *a, Instruction *b) a->next->prev = a; } +void +BasicBlock::splitCommon(Instruction *insn, BasicBlock *bb, bool attach) +{ + bb->entry = insn; + + if (insn) { + exit = insn->prev; + insn->prev = NULL; + } + + if (exit) + exit->next = NULL; + else + entry = NULL; + + while (!cfg.outgoing(true).end()) { + Graph::Edge *e = cfg.outgoing(true).getEdge(); + bb->cfg.attach(e->getTarget(), e->getType()); + this->cfg.detach(e->getTarget()); + } + + for (; insn; insn = insn->next) { + this->numInsns--; + bb->numInsns++; + insn->bb = bb; + bb->exit = insn; + } + if (attach) + this->cfg.attach(&bb->cfg, Graph::Edge::TREE); +} + +BasicBlock * +BasicBlock::splitBefore(Instruction *insn, bool attach) +{ + BasicBlock *bb = new BasicBlock(func); + assert(!insn || insn->op != OP_PHI); + + splitCommon(insn, bb, attach); + return bb; +} + +BasicBlock * +BasicBlock::splitAfter(Instruction *insn, bool attach) +{ + BasicBlock *bb = new BasicBlock(func); + assert(!insn || insn->op != OP_PHI); + + bb->joinAt = joinAt; + joinAt = NULL; + + splitCommon(insn ? insn->next : NULL, bb, attach); + return bb; +} + bool BasicBlock::dominatedBy(BasicBlock *that) { diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir_graph.h b/src/gallium/drivers/nv50/codegen/nv50_ir_graph.h index 640f518500f..7f5f03902e3 100644 --- a/src/gallium/drivers/nv50/codegen/nv50_ir_graph.h +++ b/src/gallium/drivers/nv50/codegen/nv50_ir_graph.h @@ -80,10 +80,18 @@ public: class EdgeIterator : public Iterator { public: - EdgeIterator() : e(0), t(0), d(0) { } - EdgeIterator(Graph::Edge *first, int dir) : e(first), t(first), d(dir) { } + EdgeIterator() : e(0), t(0), d(0), rev(false) { } + EdgeIterator(Graph::Edge *first, int dir, bool reverse) + : d(dir), rev(reverse) + { + t = e = ((rev && first) ? first->prev[d] : first); + } - virtual void next() { e = (e->next[d] == t) ? 0 : e->next[d]; } + virtual void next() + { + Graph::Edge *n = (rev ? e->prev[d] : e->next[d]); + e = (n == t ? NULL : n); + } virtual bool end() const { return !e; } virtual void *get() const { return e; } @@ -96,6 +104,7 @@ public: Graph::Edge *e; Graph::Edge *t; int d; + bool rev; }; class Node @@ -108,8 +117,8 @@ public: bool detach(Node *); void cut(); - inline EdgeIterator outgoing() const; - inline EdgeIterator incident() const; + inline EdgeIterator outgoing(bool reverse = false) const; + inline EdgeIterator incident(bool reverse = false) const; inline Node *parent() const; // returns NULL if count(incident edges) != 1 @@ -204,14 +213,14 @@ void Graph::putIterator(Iterator *iter) delete reinterpret_cast(iter); } -Graph::EdgeIterator Graph::Node::outgoing() const +Graph::EdgeIterator Graph::Node::outgoing(bool reverse) const { - return EdgeIterator(out, 0); + return EdgeIterator(out, 0, reverse); } -Graph::EdgeIterator Graph::Node::incident() const +Graph::EdgeIterator Graph::Node::incident(bool reverse) const { - return EdgeIterator(in, 1); + return EdgeIterator(in, 1, reverse); } int Graph::Node::incidentCountFwd() const -- 2.30.2