Gallivm: port to llvm 2.4.
[mesa.git] / src / gallium / auxiliary / gallivm / instructionssoa.cpp
index 55fdda279162df261e36e95fc007cc9d3fb0f0ef..5863f370954d877c578155d17145042b676319ac 100644 (file)
@@ -29,7 +29,7 @@
 #include "storagesoa.h"
 
 #include "pipe/p_shader_tokens.h"
-#include "pipe/p_util.h"
+#include "util/u_memory.h"
 
 #include <llvm/CallingConv.h>
 #include <llvm/Constants.h>
@@ -179,6 +179,8 @@ void InstructionsSoa::createFunctionMap()
    m_functionsMap[TGSI_OPCODE_MIN]   = "min";
    m_functionsMap[TGSI_OPCODE_MAX]   = "max";
    m_functionsMap[TGSI_OPCODE_POWER] = "pow";
+   m_functionsMap[TGSI_OPCODE_LIT]   = "lit";
+   m_functionsMap[TGSI_OPCODE_RSQ]   = "rsq";
 }
 
 void InstructionsSoa::createDependencies()
@@ -190,8 +192,9 @@ void InstructionsSoa::createDependencies()
       m_builtinDependencies["pow"] = powDeps;
    }
    {
-      std::vector<std::string> absDeps(1);
+      std::vector<std::string> absDeps(2);
       absDeps[0] = "fabsf";
+      absDeps[1] = "absvec";
       m_builtinDependencies["abs"] = absDeps;
    }
    {
@@ -204,6 +207,22 @@ void InstructionsSoa::createDependencies()
       minDeps[0] = "minvec";
       m_builtinDependencies["min"] = minDeps;
    }
+   {
+      std::vector<std::string> litDeps(4);
+      litDeps[0] = "minvec";
+      litDeps[1] = "maxvec";
+      litDeps[2] = "powf";
+      litDeps[3] = "powvec";
+      m_builtinDependencies["lit"] = litDeps;
+   }
+   {
+      std::vector<std::string> rsqDeps(4);
+      rsqDeps[0] = "sqrtf";
+      rsqDeps[1] = "sqrtvec";
+      rsqDeps[2] = "fabsf";
+      rsqDeps[3] = "absvec";
+      m_builtinDependencies["rsq"] = rsqDeps;
+   }
 }
 
 llvm::Function * InstructionsSoa::function(int op)
@@ -439,12 +458,14 @@ void InstructionsSoa::injectFunction(llvm::Function *originalFunc, int op)
       func = Function::Create(originalFunc->getFunctionType(), GlobalValue::ExternalLinkage,
                               originalFunc->getName(), currentModule());
       func->setCallingConv(CallingConv::C);
-      const PAListPtr pal;
-      func->setParamAttrs(pal);
+      const AttrListPtr pal;
+      func->setAttributes(pal);
       currentModule()->dump();
    } else {
       DenseMap<const Value*, Value *> val;
+      val[m_builtins->getFunction("fabsf")] = currentModule()->getFunction("fabsf");
       val[m_builtins->getFunction("powf")] = currentModule()->getFunction("powf");
+      val[m_builtins->getFunction("sqrtf")] = currentModule()->getFunction("sqrtf");
       func = CloneFunction(originalFunc, val);
 #if 0
       std::cout <<" replacing "<<m_builtins->getFunction("powf")
@@ -475,3 +496,15 @@ std::vector<llvm::Value*> InstructionsSoa::sub(const std::vector<llvm::Value*> i
    return res;
 }
 
+std::vector<llvm::Value*> InstructionsSoa::lit(const std::vector<llvm::Value*> in)
+{
+   llvm::Function *func = function(TGSI_OPCODE_LIT);
+   return callBuiltin(func, in);
+}
+
+std::vector<llvm::Value*> InstructionsSoa::rsq(const std::vector<llvm::Value*> in)
+{
+   llvm::Function *func = function(TGSI_OPCODE_RSQ);
+   return callBuiltin(func, in);
+}
+