nv50/ir: fix off-by-ones in CSE and nvc0 insnCanLoad
[mesa.git] / src / gallium / drivers / nv50 / codegen / nv50_ir_bb.cpp
index 07d8decee54293504b63160bfaa8ddccfb25d249..ebfb07a2b3ecbac66f9d6c18ebe750af1a879103 100644 (file)
@@ -24,8 +24,9 @@
 
 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)
 {
@@ -40,11 +41,17 @@ 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)
@@ -402,19 +409,39 @@ Function::setExit(BasicBlock *bb)
 unsigned int
 Function::orderInstructions(ArrayList &result)
 {
-   Iterator *iter;
-   for (iter = cfg.iteratorCFG(); !iter->end(); iter->next()) {
+   result.clear();
+
+   for (IteratorRef it = cfg.iteratorCFG(); !it->end(); it->next()) {
       BasicBlock *bb =
-         BasicBlock::get(reinterpret_cast<Graph::Node *>(iter->get()));
+         BasicBlock::get(reinterpret_cast<Graph::Node *>(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)
 {
@@ -426,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<Function *>(fi.get());
-      if (!doRun(fn, ordered, skipPhi))
+   for (IteratorRef it = prog->calls.iteratorDFS(false);
+        !it->end(); it->next()) {
+      Graph::Node *n = reinterpret_cast<Graph::Node *>(it->get());
+      if (!doRun(Function::get(n), ordered, skipPhi))
          return false;
    }
    return !err;
@@ -446,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;
 
@@ -467,7 +494,7 @@ Pass::doRun(Function *func, bool ordered, bool skipPhi)
             break;
       }
    }
-   func->cfg.putIterator(bbIter);
+
    return !err;
 }
 
@@ -483,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<Graph::Node *>(iter->get()));
+         reinterpret_cast<Graph::Node *>(it->get()));
       int idA = bb->getId();
       for (Graph::EdgeIterator ei = bb->cfg.outgoing(); !ei.end(); ei.next()) {
          int idB = BasicBlock::get(ei.getNode())->getId();
@@ -512,7 +538,6 @@ Function::printCFGraph(const char *filePath)
          }
       }
    }
-   cfg.putIterator(iter);
 
    fprintf(out, "}\n");
    fclose(out);