X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fnv50%2Fcodegen%2Fnv50_ir_bb.cpp;h=ebfb07a2b3ecbac66f9d6c18ebe750af1a879103;hb=15ce0f76e2e014374a292550505f58da88333fb7;hp=5bf08b37c51be2199258f5c5f9ff51b3fa1bee2d;hpb=57594065c30feec9376be9b2132659f7d87362ee;p=mesa.git diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir_bb.cpp b/src/gallium/drivers/nv50/codegen/nv50_ir_bb.cpp index 5bf08b37c51..ebfb07a2b3e 100644 --- a/src/gallium/drivers/nv50/codegen/nv50_ir_bb.cpp +++ b/src/gallium/drivers/nv50/codegen/nv50_ir_bb.cpp @@ -1,10 +1,32 @@ +/* + * Copyright 2011 Christoph Bumiller + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ #include "nv50_ir.h" namespace nv50_ir { -Function::Function(Program *p, const char *fnName) +Function::Function(Program *p, const char *fnName, uint32_t label) : call(this), + label(label), name(fnName), prog(p) { @@ -19,16 +41,28 @@ Function::Function(Program *p, const char *fnName) binPos = 0; binSize = 0; + stackPtr = NULL; + tlsBase = 0; + tlsSize = 0; + prog->add(this, id); } Function::~Function() { + prog->del(this, id); + if (domTree) delete domTree; if (bbArray) delete[] bbArray; + for (ArrayList::Iterator it = allInsns.iterator(); !it.end(); it.next()) + delete_Instruction(prog, reinterpret_cast(it.get())); + + for (ArrayList::Iterator it = allLValues.iterator(); !it.end(); it.next()) + delete_Value(prog, reinterpret_cast(it.get())); + for (ArrayList::Iterator BBs = allBBlocks.iterator(); !BBs.end(); BBs.next()) delete reinterpret_cast(BBs.get()); } @@ -53,6 +87,26 @@ BasicBlock::~BasicBlock() // nothing yet } +BasicBlock * +BasicBlock::clone(ClonePolicy& pol) const +{ + BasicBlock *bb = new BasicBlock(pol.context()); + + pol.set(this, bb); + + for (Instruction *i = getFirst(); i; i = i->next) + bb->insertTail(i->clone(pol)); + + pol.context()->cfg.insert(&bb->cfg); + + for (Graph::EdgeIterator it = cfg.outgoing(); !it.end(); it.next()) { + BasicBlock *obb = BasicBlock::get(it.getNode()); + bb->cfg.attach(&pol.get(obb)->cfg, it.getType()); + } + + return bb; +} + BasicBlock * BasicBlock::idom() const { @@ -70,7 +124,7 @@ BasicBlock::insertHead(Instruction *inst) insertBefore(phi, inst); } else { if (entry) { - insertBefore(entry, phi); + insertBefore(entry, inst); } else { assert(!exit); phi = exit = inst; @@ -83,7 +137,7 @@ BasicBlock::insertHead(Instruction *inst) insertBefore(entry, inst); } else { if (phi) { - insertAfter(phi, inst); + insertAfter(exit, inst); // after last phi } else { assert(!exit); entry = exit = inst; @@ -190,8 +244,15 @@ BasicBlock::remove(Instruction *insn) else exit = insn->prev; - if (insn == entry) - entry = insn->next ? insn->next : insn->prev; + if (insn == entry) { + if (insn->next) + entry = insn->next; + else + if (insn->prev && insn->prev->op != OP_PHI) + entry = insn->prev; + else + entry = NULL; + } if (insn == phi) phi = (insn->next && insn->next->op == OP_PHI) ? insn->next : 0; @@ -230,6 +291,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) { @@ -294,15 +409,39 @@ Function::setExit(BasicBlock *bb) unsigned int Function::orderInstructions(ArrayList &result) { - Iterator *iter; - for (iter = cfg.iteratorCFG(); !iter->end(); iter->next()) - for (Instruction *insn = BasicBlock::get(*iter)->getFirst(); - insn; insn = insn->next) + result.clear(); + + for (IteratorRef it = cfg.iteratorCFG(); !it->end(); it->next()) { + BasicBlock *bb = + BasicBlock::get(reinterpret_cast(it->get())); + + for (Instruction *insn = bb->getFirst(); insn; insn = insn->next) result.insert(insn, insn->serial); - cfg.putIterator(iter); + } + return result.getSize(); } +void +Function::buildLiveSets() +{ + for (unsigned i = 0; i <= loopNestingBound; ++i) + buildLiveSetsPreSSA(BasicBlock::get(cfg.getRoot()), cfg.nextSequence()); + + for (ArrayList::Iterator bi = allBBlocks.iterator(); !bi.end(); bi.next()) + BasicBlock::get(bi)->liveSet.marker = false; +} + +void +Function::buildDefSets() +{ + for (unsigned i = 0; i <= loopNestingBound; ++i) + buildDefSetsPreSSA(BasicBlock::get(cfgExit), cfg.nextSequence()); + + for (ArrayList::Iterator bi = allBBlocks.iterator(); !bi.end(); bi.next()) + BasicBlock::get(bi)->liveSet.marker = false; +} + bool Pass::run(Program *prog, bool ordered, bool skipPhi) { @@ -314,10 +453,10 @@ Pass::run(Program *prog, bool ordered, bool skipPhi) bool Pass::doRun(Program *prog, bool ordered, bool skipPhi) { - for (ArrayList::Iterator fi = prog->allFuncs.iterator(); - !fi.end(); fi.next()) { - Function *fn = reinterpret_cast(fi.get()); - if (!doRun(fn, ordered, skipPhi)) + for (IteratorRef it = prog->calls.iteratorDFS(false); + !it->end(); it->next()) { + Graph::Node *n = reinterpret_cast(it->get()); + if (!doRun(Function::get(n), ordered, skipPhi)) return false; } return !err; @@ -334,7 +473,7 @@ Pass::run(Function *func, bool ordered, bool skipPhi) bool Pass::doRun(Function *func, bool ordered, bool skipPhi) { - Iterator *bbIter; + IteratorRef bbIter; BasicBlock *bb; Instruction *insn, *next; @@ -355,7 +494,7 @@ Pass::doRun(Function *func, bool ordered, bool skipPhi) break; } } - func->cfg.putIterator(bbIter); + return !err; } @@ -371,10 +510,9 @@ Function::printCFGraph(const char *filePath) fprintf(out, "digraph G {\n"); - Iterator *iter; - for (iter = cfg.iteratorDFS(); !iter->end(); iter->next()) { + for (IteratorRef it = cfg.iteratorDFS(); !it->end(); it->next()) { BasicBlock *bb = BasicBlock::get( - reinterpret_cast(iter->get())); + reinterpret_cast(it->get())); int idA = bb->getId(); for (Graph::EdgeIterator ei = bb->cfg.outgoing(); !ei.end(); ei.next()) { int idB = BasicBlock::get(ei.getNode())->getId(); @@ -400,7 +538,6 @@ Function::printCFGraph(const char *filePath) } } } - cfg.putIterator(iter); fprintf(out, "}\n"); fclose(out);