Hold a stack of temporaries so that we can redeclare them
authorZack Rusin <zack@tungstengraphics.com>
Fri, 26 Oct 2007 23:12:02 +0000 (19:12 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Fri, 26 Oct 2007 23:12:56 +0000 (19:12 -0400)
for all defined functions. Fixes crashes in function calls.

src/mesa/pipe/llvm/llvmtgsi.cpp
src/mesa/pipe/llvm/storage.cpp
src/mesa/pipe/llvm/storage.h

index cfeb19e4ba8867cc0c652351fc434ee0452cebf5..af602326ae64f4258c2ac9cae88ca6f768e21781 100644 (file)
@@ -508,19 +508,21 @@ translate_instruction(llvm::Module *module,
    case TGSI_OPCODE_BGNSUB: {
       instr->bgnSub(instno, storage);
       storage->setCurrentBlock(instr->currentBlock());
+      storage->pushTemps();
       return;
    }
       break;
    case TGSI_OPCODE_ENDLOOP2: {
       instr->endLoop();
       storage->setCurrentBlock(instr->currentBlock());
-      storage->popArguments();
       return;
    }
       break;
    case TGSI_OPCODE_ENDSUB: {
       instr->endSub();
       storage->setCurrentBlock(instr->currentBlock());
+      storage->popArguments();
+      storage->popTemps();
       return;
    }
       break;
index 88ef6711cfb1b1ffb4d149145ddd650178e1f0e6..7300cdfef0638a3bf702c0822bf48d6ceeba7152 100644 (file)
@@ -369,3 +369,24 @@ void Storage::popArguments()
    m_CONST = arg.cst;
    m_argStack.pop();
 }
+
+void Storage::pushTemps()
+{
+   m_tempStack.push(m_temps);
+   std::vector<llvm::Value*> oldTemps = m_temps;
+   m_temps = std::vector<llvm::Value*>(32);
+   int i = 0;
+   for (std::vector<llvm::Value*>::iterator itr = oldTemps.begin();
+        itr != oldTemps.end(); ++itr) {
+      if (*itr) {
+         declareTemp(i);
+      }
+      ++i;
+   }
+}
+
+void Storage::popTemps()
+{
+   m_temps = m_tempStack.top();
+   m_tempStack.pop();
+}
index b8d6eb06049f061001c93356009a7287684f1485..eeadaa0506a98b77088c4d036725844b014ff909 100644 (file)
@@ -84,6 +84,8 @@ public:
    void pushArguments(llvm::Value *out, llvm::Value *in,
                       llvm::Value *constPtr);
    void popArguments();
+   void pushTemps();
+   void popTemps();
 
 private:
    llvm::Value *maskWrite(llvm::Value *src, int mask, llvm::Value *templ);
@@ -122,6 +124,7 @@ private:
       llvm::Value *cst;
    };
    std::stack<Args> m_argStack;
+   std::stack<std::vector<llvm::Value*> > m_tempStack;
 };
 
 #endif