make the first builtin work (dp3)
authorZack Rusin <zack@pixel.(none)>
Sat, 1 Mar 2008 13:32:31 +0000 (08:32 -0500)
committerZack Rusin <zack@tungstengraphics.com>
Sat, 1 Mar 2008 20:28:00 +0000 (15:28 -0500)
src/gallium/auxiliary/gallivm/gallivm.cpp
src/gallium/auxiliary/gallivm/instructionssoa.cpp

index d14bb3b99a877feb71b460ac2639475d9117a647..b6f641a3f86d197db53e32936c1587a0299116fb 100644 (file)
@@ -306,11 +306,19 @@ struct gallivm_prog * gallivm_ir_compile(struct gallivm_ir *ir)
 {
    struct gallivm_prog *prog =
       (struct gallivm_prog *)calloc(1, sizeof(struct gallivm_prog));
+   
+   std::cout << "Before optimizations:"<<std::endl;
+   ir->module->dump();
+   std::cout<<"-------------------------------"<<std::endl;
+   
+   PassManager veri;
+   veri.add(createVerifierPass());
+   veri.run(*ir->module);
    llvm::Module *mod = llvm::CloneModule(ir->module);
    prog->num_consts = ir->num_consts;
    memcpy(prog->interpolators, ir->interpolators, sizeof(prog->interpolators));
    prog->num_interp = ir->num_interp;
-
+   
    /* Run optimization passes over it */
    PassManager passes;
    passes.add(new TargetData(mod));
index 5739cf0cdef97daa94432ea7f43e74706677dea8..3fcfce8ce01765f1db6dd429b0bb957b24e08493 100644 (file)
@@ -158,6 +158,7 @@ llvm::Function * InstructionsSoa::function(int op)
     currentModule()->getFunctionList().push_back(func);
     std::cout << "Func parent is "<<func->getParent()
               <<", cur is "<<currentModule() <<std::endl;
+    func->dump();
        //func->setParent(currentModule());
     m_functions[op] = func;
     return func;
@@ -184,8 +185,15 @@ std::vector<llvm::Value*> InstructionsSoa::dp3(const std::vector<llvm::Value*> i
    std::vector<Value*> params;
 
    llvm::Value *tmp = allocaTemp();
-   params.push_back(tmp);
-
+   std::vector<Value*> indices;
+   indices.push_back(m_storage->constantInt(0));
+   indices.push_back(m_storage->constantInt(0));
+   GetElementPtrInst *getElem = new GetElementPtrInst(tmp,
+                                                      indices.begin(),
+                                                      indices.end(),
+                                                      name("allocaPtr"),
+                                                      m_builder.GetInsertBlock());
+   params.push_back(getElem);
    params.push_back(in1[0]);
    params.push_back(in1[1]);
    params.push_back(in1[2]);
@@ -194,20 +202,10 @@ std::vector<llvm::Value*> InstructionsSoa::dp3(const std::vector<llvm::Value*> i
    params.push_back(in2[1]);
    params.push_back(in2[2]);
    params.push_back(in2[3]);
-   CallInst *call = m_builder.CreateCall(func, params.begin(), params.end(),
-                                         name("dp3"));
+   CallInst *call = m_builder.CreateCall(func, params.begin(), params.end());
    call->setCallingConv(CallingConv::C);
    call->setTailCall(false);
 
-   std::vector<Value*> indices;
-   indices.push_back(m_storage->constantInt(0));
-   indices.push_back(m_storage->constantInt(0));
-
-   GetElementPtrInst *getElem = new GetElementPtrInst(tmp,
-                                                      indices.begin(),
-                                                      indices.end(),
-                                                      name("allocaPtr"),
-                                                      m_builder.GetInsertBlock());
    indices = std::vector<Value*>();
    indices.push_back(m_storage->constantInt(0));
    GetElementPtrInst *xElemPtr =  new GetElementPtrInst(getElem,
@@ -228,10 +226,19 @@ std::vector<llvm::Value*> InstructionsSoa::dp3(const std::vector<llvm::Value*> i
                                                         m_builder.GetInsertBlock());
 
    std::vector<llvm::Value*> res(4);
-   res[0] = new LoadInst(xElemPtr);
-   res[1] = new LoadInst(yElemPtr);
-   res[2] = new LoadInst(zElemPtr);
-   res[3] = new LoadInst(wElemPtr);
+   res[0] = new LoadInst(xElemPtr, name("xRes"), false, m_builder.GetInsertBlock());
+   res[1] = new LoadInst(yElemPtr, name("yRes"), false, m_builder.GetInsertBlock());
+   res[2] = new LoadInst(zElemPtr, name("zRes"), false, m_builder.GetInsertBlock());
+   res[3] = new LoadInst(wElemPtr, name("wRes"), false, m_builder.GetInsertBlock());
 
    return res;
 }
+
+llvm::Value * InstructionsSoa::allocaTemp()
+{
+   VectorType *vector   = VectorType::get(Type::FloatTy, 4);
+   ArrayType  *vecArray = ArrayType::get(vector, 4);
+   AllocaInst *alloca = new AllocaInst(vecArray, name("tmpRes"),
+                                       m_builder.GetInsertBlock());
+   return alloca;
+}