fix injections of functions from builtins into shaders
authorZack Rusin <zack@tungstengraphics.com>
Thu, 15 May 2008 18:11:19 +0000 (14:11 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Sat, 17 May 2008 17:58:44 +0000 (13:58 -0400)
src/gallium/auxiliary/gallivm/gallivm.cpp
src/gallium/auxiliary/gallivm/instructionssoa.cpp

index b6f641a3f86d197db53e32936c1587a0299116fb..48a3b18cdc9e40cc586c953bc222cba4038115a0 100644 (file)
@@ -288,10 +288,7 @@ void gallivm_ir_fill_from_tgsi(struct gallivm_ir *ir,
    std::cout << "Creating llvm from: " <<std::endl;
    tgsi_dump(tokens, 0);
 
-
    llvm::Module *mod = tgsi_to_llvmir(ir, tokens);
-
-   //llvm::Module *mod = tgsi_to_llvm(ir, tokens);
    ir->module = mod;
    gallivm_ir_dump(ir, 0);
 }
index f0122802db952c473de2ac5e7c28e6259d12f46b..17e876e32d21f1b9f11980c91b0311866d15a64e 100644 (file)
@@ -38,7 +38,6 @@
 #include <llvm/Instructions.h>
 #include <llvm/Transforms/Utils/Cloning.h>
 #include <llvm/ParameterAttributes.h>
-//#include <llvm/ParamAttrsList.h>
 #include <llvm/Support/MemoryBuffer.h>
 #include <llvm/Bitcode/ReaderWriter.h>
 
@@ -193,9 +192,13 @@ llvm::Function * InstructionsSoa::function(int op)
 
     std::string name = m_functionsMap[op];
 
+    std::cout <<"For op = "<<op<<", func is '"<<name<<"'"<<std::endl;
+
     std::vector<std::string> deps = m_builtinDependencies[name];
     for (unsigned int i = 0; i < deps.size(); ++i) {
-       injectFunction(m_builtins->getFunction(deps[i]));
+       llvm::Function *func = m_builtins->getFunction(deps[i]);
+       std::cout <<"\tinjecting dep = '"<<func->getName()<<"'"<<std::endl;
+       injectFunction(func);
     }
 
     llvm::Function *originalFunc = m_builtins->getFunction(name);
@@ -216,8 +219,10 @@ void InstructionsSoa::createBuiltins()
 {
    MemoryBuffer *buffer = MemoryBuffer::getMemBuffer(
       (const char*)&soabuiltins_data[0],
-      (const char*)&soabuiltins_data[Elements(soabuiltins_data)-1]);
+      (const char*)&soabuiltins_data[Elements(soabuiltins_data)]);
    m_builtins = ParseBitcodeFile(buffer);
+   std::cout<<"Builtins created at "<<m_builtins<<std::endl;
+   assert(m_builtins);
    createDependencies();
 }
 
@@ -388,7 +393,6 @@ void InstructionsSoa::injectFunction(llvm::Function *originalFunc, int op)
    }
    llvm::Function *func = 0;
    if (originalFunc->isDeclaration()) {
-      std::cout << "function decleration" <<std::endl;
       func = Function::Create(originalFunc->getFunctionType(), GlobalValue::ExternalLinkage,
                               originalFunc->getName(), currentModule());
       func->setCallingConv(CallingConv::C);
@@ -398,17 +402,17 @@ void InstructionsSoa::injectFunction(llvm::Function *originalFunc, int op)
    } else {
       DenseMap<const Value*, Value *> val;
       val[m_builtins->getFunction("powf")] = currentModule()->getFunction("powf");
+      func = CloneFunction(originalFunc, val);
+#if 0
       std::cout <<" replacing "<<m_builtins->getFunction("powf")
                 <<", with " <<currentModule()->getFunction("powf")<<std::endl;
-      func = CloneFunction(originalFunc, val);
       std::cout<<"1111-------------------------------"<<std::endl;
       checkFunction(originalFunc);
       std::cout<<"2222-------------------------------"<<std::endl;
       checkFunction(func);
       std::cout <<"XXXX = " <<val[m_builtins->getFunction("powf")]<<std::endl;
+#endif
       currentModule()->getFunctionList().push_back(func);
-      std::cout << "Func parent is "<<func->getParent()
-                <<", cur is "<<currentModule() <<std::endl;
    }
    if (op != TGSI_OPCODE_LAST) {
       m_functions[op] = func;