nv50/ir: Scan program functions in DFS-postorder.
authorFrancisco Jerez <currojerez@riseup.net>
Mon, 9 Apr 2012 19:18:31 +0000 (21:18 +0200)
committerChristoph Bumiller <e0425955@student.tuwien.ac.at>
Sat, 14 Apr 2012 19:54:01 +0000 (21:54 +0200)
The reason is that several passes (regalloc, function argument
binding, inlining) are going to require the callees of a function to
be processed before the caller.

src/gallium/drivers/nv50/codegen/nv50_ir.cpp
src/gallium/drivers/nv50/codegen/nv50_ir.h
src/gallium/drivers/nv50/codegen/nv50_ir_bb.cpp
src/gallium/drivers/nv50/codegen/nv50_ir_inlines.h
src/gallium/drivers/nv50/codegen/nv50_ir_ra.cpp

index cbab1ec..357d6d9 100644 (file)
@@ -977,6 +977,7 @@ Program::Program(Type type, Target *arch)
    maxGPR = -1;
 
    main = new Function(this, "MAIN");
+   calls.insert(&main->call);
 
    dbgFlags = 0;
 }
index 74692d8..e803a8b 100644 (file)
@@ -919,6 +919,8 @@ public:
    Function(Program *, const char *name);
    ~Function();
 
+   static inline Function *get(Graph::Node *node);
+
    inline Program *getProgram() const { return prog; }
    inline const char *getName() const { return name; }
    inline int getId() const { return id; }
index 991341b..5a76558 100644 (file)
@@ -444,10 +444,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;
index 4aec6ea..b06f217 100644 (file)
@@ -358,6 +358,12 @@ BasicBlock *BasicBlock::get(Graph::Node *node)
    return reinterpret_cast<BasicBlock *>(node->data);
 }
 
+Function *Function::get(Graph::Node *node)
+{
+   assert(node);
+   return reinterpret_cast<Function *>(node->data);
+}
+
 LValue *Function::getLValue(int id)
 {
    assert((unsigned int)id < (unsigned int)allLValues.getSize());
index 43c29d5..a91a088 100644 (file)
@@ -724,9 +724,9 @@ RegAlloc::linearScan()
 bool
 RegAlloc::exec()
 {
-   for (ArrayList::Iterator fi = prog->allFuncs.iterator();
-        !fi.end(); fi.next()) {
-      func = reinterpret_cast<Function *>(fi.get());
+   for (IteratorRef it = prog->calls.iteratorDFS(false);
+        !it->end(); it->next()) {
+      func = Function::get(reinterpret_cast<Graph::Node *>(it->get()));
       if (!execFunc())
          return false;
    }