summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/llvm
diff options
context:
space:
mode:
authorZack Rusin <zack@tungstengraphics.com>2007-10-30 07:16:22 -0400
committerZack Rusin <zack@tungstengraphics.com>2007-10-30 07:16:22 -0400
commitdfd774318d1549c1e52364870a2c16a220dcd64c (patch)
treecb5bdb984f838fd998879b92c0464119c4099d7d /src/mesa/pipe/llvm
parenta01341a762baf7d5e18bd1a55950da7958958927 (diff)
Export true C based builtins to a file of its own.
Diffstat (limited to 'src/mesa/pipe/llvm')
-rw-r--r--src/mesa/pipe/llvm/gallivm_builtins.cpp151
-rw-r--r--src/mesa/pipe/llvm/instructions.cpp181
-rw-r--r--src/mesa/pipe/llvm/llvm_builtins.c59
3 files changed, 215 insertions, 176 deletions
diff --git a/src/mesa/pipe/llvm/gallivm_builtins.cpp b/src/mesa/pipe/llvm/gallivm_builtins.cpp
new file mode 100644
index 0000000000..4acbedc566
--- /dev/null
+++ b/src/mesa/pipe/llvm/gallivm_builtins.cpp
@@ -0,0 +1,151 @@
+// Generated by llvm2cpp - DO NOT MODIFY!
+
+
+Module* createGallivmBuiltins(Module *mod) {
+
+mod->setModuleIdentifier("shader");
+
+// Type Definitions
+std::vector<const Type*>FuncTy_0_args;
+FuncTy_0_args.push_back(Type::FloatTy);
+FuncTy_0_args.push_back(Type::FloatTy);
+ParamAttrsList *FuncTy_0_PAL = 0;
+FunctionType* FuncTy_0 = FunctionType::get(
+ /*Result=*/Type::FloatTy,
+ /*Params=*/FuncTy_0_args,
+ /*isVarArg=*/false,
+ /*ParamAttrs=*/FuncTy_0_PAL);
+
+PointerType* PointerTy_1 = PointerType::get(FuncTy_0);
+
+VectorType* VectorTy_2 = VectorType::get(Type::FloatTy, 4);
+
+std::vector<const Type*>FuncTy_3_args;
+FuncTy_3_args.push_back(VectorTy_2);
+ParamAttrsList *FuncTy_3_PAL = 0;
+FunctionType* FuncTy_3 = FunctionType::get(
+ /*Result=*/VectorTy_2,
+ /*Params=*/FuncTy_3_args,
+ /*isVarArg=*/false,
+ /*ParamAttrs=*/FuncTy_3_PAL);
+
+
+// Function Declarations
+
+Function* func_approx = new Function(
+ /*Type=*/FuncTy_0,
+ /*Linkage=*/GlobalValue::ExternalLinkage,
+ /*Name=*/"approx", mod);
+func_approx->setCallingConv(CallingConv::C);
+
+Function* func_powf = new Function(
+ /*Type=*/FuncTy_0,
+ /*Linkage=*/GlobalValue::ExternalLinkage,
+ /*Name=*/"powf", mod); // (external, no body)
+func_powf->setCallingConv(CallingConv::C);
+
+Function* func_lit = new Function(
+ /*Type=*/FuncTy_3,
+ /*Linkage=*/GlobalValue::ExternalLinkage,
+ /*Name=*/"lit", mod);
+func_lit->setCallingConv(CallingConv::C);
+
+// Global Variable Declarations
+
+
+// Constant Definitions
+ConstantFP* const_float_4 = ConstantFP::get(Type::FloatTy, APFloat(-1.280000e+02f));
+ConstantFP* const_float_5 = ConstantFP::get(Type::FloatTy, APFloat(1.280000e+02f));
+Constant* const_float_6 = Constant::getNullValue(Type::FloatTy);
+Constant* const_int32_7 = Constant::getNullValue(IntegerType::get(32));
+std::vector<Constant*> const_packed_8_elems;
+ConstantFP* const_float_9 = ConstantFP::get(Type::FloatTy, APFloat(1.000000e+00f));
+const_packed_8_elems.push_back(const_float_9);
+UndefValue* const_float_10 = UndefValue::get(Type::FloatTy);
+const_packed_8_elems.push_back(const_float_10);
+const_packed_8_elems.push_back(const_float_10);
+const_packed_8_elems.push_back(const_float_9);
+Constant* const_packed_8 = ConstantVector::get(VectorTy_2, const_packed_8_elems);
+ConstantInt* const_int32_11 = ConstantInt::get(APInt(32, "1", 10));
+ConstantInt* const_int32_12 = ConstantInt::get(APInt(32, "3", 10));
+ConstantInt* const_int32_13 = ConstantInt::get(APInt(32, "2", 10));
+std::vector<Constant*> const_packed_14_elems;
+const_packed_14_elems.push_back(const_float_9);
+const_packed_14_elems.push_back(const_float_6);
+const_packed_14_elems.push_back(const_float_6);
+const_packed_14_elems.push_back(const_float_9);
+Constant* const_packed_14 = ConstantVector::get(VectorTy_2, const_packed_14_elems);
+
+// Global Variable Definitions
+
+// Function Definitions
+
+// Function: approx (func_approx)
+{
+ Function::arg_iterator args = func_approx->arg_begin();
+ Value* float_a = args++;
+ float_a->setName("a");
+ Value* float_b = args++;
+ float_b->setName("b");
+
+ BasicBlock* label_entry = new BasicBlock("entry",func_approx,0);
+
+ // Block entry (label_entry)
+ FCmpInst* int1_cmp = new FCmpInst(FCmpInst::FCMP_OLT, float_b, const_float_4, "cmp", label_entry);
+ SelectInst* float_b_addr_0 = new SelectInst(int1_cmp, const_float_4, float_b, "b.addr.0", label_entry);
+ FCmpInst* int1_cmp3 = new FCmpInst(FCmpInst::FCMP_OGT, float_b_addr_0, const_float_5, "cmp3", label_entry);
+ SelectInst* float_b_addr_1 = new SelectInst(int1_cmp3, const_float_5, float_b_addr_0, "b.addr.1", label_entry);
+ FCmpInst* int1_cmp7 = new FCmpInst(FCmpInst::FCMP_OLT, float_a, const_float_6, "cmp7", label_entry);
+ SelectInst* float_a_addr_0 = new SelectInst(int1_cmp7, const_float_6, float_a, "a.addr.0", label_entry);
+ std::vector<Value*> float_call_params;
+ float_call_params.push_back(float_a_addr_0);
+ float_call_params.push_back(float_b_addr_1);
+ CallInst* float_call = new CallInst(func_powf, float_call_params.begin(), float_call_params.end(), "call", label_entry);
+ float_call->setCallingConv(CallingConv::C);
+ float_call->setTailCall(true);
+ new ReturnInst(float_call, label_entry);
+
+}
+
+// Function: lit (func_lit)
+{
+ Function::arg_iterator args = func_lit->arg_begin();
+ Value* packed_tmp = args++;
+ packed_tmp->setName("tmp");
+
+ BasicBlock* label_entry_16 = new BasicBlock("entry",func_lit,0);
+ BasicBlock* label_ifthen = new BasicBlock("ifthen",func_lit,0);
+ BasicBlock* label_UnifiedReturnBlock = new BasicBlock("UnifiedReturnBlock",func_lit,0);
+
+ // Block entry (label_entry_16)
+ ExtractElementInst* float_tmp7 = new ExtractElementInst(packed_tmp, const_int32_7, "tmp7", label_entry_16);
+ FCmpInst* int1_cmp_17 = new FCmpInst(FCmpInst::FCMP_OGT, float_tmp7, const_float_6, "cmp", label_entry_16);
+ new BranchInst(label_ifthen, label_UnifiedReturnBlock, int1_cmp_17, label_entry_16);
+
+ // Block ifthen (label_ifthen)
+ InsertElementInst* packed_tmp12 = new InsertElementInst(const_packed_8, float_tmp7, const_int32_11, "tmp12", label_ifthen);
+ ExtractElementInst* float_tmp14 = new ExtractElementInst(packed_tmp, const_int32_11, "tmp14", label_ifthen);
+ ExtractElementInst* float_tmp16 = new ExtractElementInst(packed_tmp, const_int32_12, "tmp16", label_ifthen);
+ FCmpInst* int1_cmp_i = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp16, const_float_4, "cmp.i", label_ifthen);
+ SelectInst* float_b_addr_0_i = new SelectInst(int1_cmp_i, const_float_4, float_tmp16, "b.addr.0.i", label_ifthen);
+ FCmpInst* int1_cmp3_i = new FCmpInst(FCmpInst::FCMP_OGT, float_b_addr_0_i, const_float_5, "cmp3.i", label_ifthen);
+ SelectInst* float_b_addr_1_i = new SelectInst(int1_cmp3_i, const_float_5, float_b_addr_0_i, "b.addr.1.i", label_ifthen);
+ FCmpInst* int1_cmp7_i = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp14, const_float_6, "cmp7.i", label_ifthen);
+ SelectInst* float_a_addr_0_i = new SelectInst(int1_cmp7_i, const_float_6, float_tmp14, "a.addr.0.i", label_ifthen);
+ std::vector<Value*> float_call_i_params;
+ float_call_i_params.push_back(float_a_addr_0_i);
+ float_call_i_params.push_back(float_b_addr_1_i);
+ CallInst* float_call_i = new CallInst(func_powf, float_call_i_params.begin(), float_call_i_params.end(), "call.i", label_ifthen);
+ float_call_i->setCallingConv(CallingConv::C);
+ float_call_i->setTailCall(true);
+ InsertElementInst* packed_tmp18 = new InsertElementInst(packed_tmp12, float_call_i, const_int32_13, "tmp18", label_ifthen);
+ new ReturnInst(packed_tmp18, label_ifthen);
+
+ // Block UnifiedReturnBlock (label_UnifiedReturnBlock)
+ new ReturnInst(const_packed_14, label_UnifiedReturnBlock);
+
+}
+
+return mod;
+
+}
diff --git a/src/mesa/pipe/llvm/instructions.cpp b/src/mesa/pipe/llvm/instructions.cpp
index 3c68b764aa..4e116f2a98 100644
--- a/src/mesa/pipe/llvm/instructions.cpp
+++ b/src/mesa/pipe/llvm/instructions.cpp
@@ -48,7 +48,7 @@
using namespace llvm;
-Function* makeLitFunction(Module *mod);
+#include "gallivm_builtins.cpp"
static inline std::string createFuncName(int label)
{
@@ -70,6 +70,8 @@ Instructions::Instructions(llvm::Module *mod, llvm::Function *func, llvm::BasicB
m_llvmFlog = 0;
m_llvmLit = 0;
m_fmtPtr = 0;
+
+ createGallivmBuiltins(m_mod);
}
llvm::Value * Instructions::add(llvm::Value *in1, llvm::Value *in2)
@@ -214,7 +216,7 @@ llvm::Value *Instructions::callFAbs(llvm::Value *val)
llvm::Value * Instructions::lit(llvm::Value *in)
{
if (!m_llvmLit) {
- m_llvmLit = makeLitFunction(m_mod);
+ m_llvmLit = m_mod->getFunction("lit");
}
CallInst *call = new CallInst(m_llvmLit, in, name("litres"), m_block);
call->setCallingConv(CallingConv::C);
@@ -787,180 +789,6 @@ llvm::Value * Instructions::abs(llvm::Value *in)
return vectorFromVals(xabs, yabs, zabs, wabs);
}
-/*
-FIXME: hand write the lit function. Currently it's
-generated from:
-typedef __attribute__(( ocu_vector_type(4) )) float float4;
-
-extern float powf(float a, float b);
-
-inline float approx(float a, float b)
-{
- if (b < -128.0f) b = -128.0f;
- if (b > 128.0f) b = 128.0f;
- if (a < 0) a = 0;
- return powf(a, b);
-}
-
-float4 lit(float4 tmp)
-{
- float4 result;
- result.x = 1.0;
- result.w = 1.0;
- if (tmp.x > 0) {
- result.y = tmp.x;
- result.z = approx(tmp.y, tmp.w);
- } else {
- result.y = 0;
- result.z = 0;
- }
- return result;
-}
-with:
-clang --emit-llvm lit.c |llvm-as|opt -std-compile-opts|llvm2cpp -gen-contents -for=lit
-*/
-Function* makeLitFunction(Module *mod) {
-
- // Type Definitions
- std::vector<const Type*>FuncTy_0_args;
- FuncTy_0_args.push_back(Type::FloatTy);
- FuncTy_0_args.push_back(Type::FloatTy);
- ParamAttrsList *FuncTy_0_PAL = 0;
- FunctionType* FuncTy_0 = FunctionType::get(
- /*Result=*/Type::FloatTy,
- /*Params=*/FuncTy_0_args,
- /*isVarArg=*/false,
- /*ParamAttrs=*/FuncTy_0_PAL);
-
- VectorType* VectorTy_2 = VectorType::get(Type::FloatTy, 4);
-
- std::vector<const Type*>FuncTy_3_args;
- FuncTy_3_args.push_back(VectorTy_2);
- ParamAttrsList *FuncTy_3_PAL = 0;
- FunctionType* FuncTy_3 = FunctionType::get(
- /*Result=*/VectorTy_2,
- /*Params=*/FuncTy_3_args,
- /*isVarArg=*/false,
- /*ParamAttrs=*/FuncTy_3_PAL);
-
-
- // Function Declarations
-
- Function* func_approx = new Function(
- /*Type=*/FuncTy_0,
- /*Linkage=*/GlobalValue::ExternalLinkage,
- /*Name=*/"approx", mod);
- func_approx->setCallingConv(CallingConv::C);
-
- Function* func_powf = new Function(
- /*Type=*/FuncTy_0,
- /*Linkage=*/GlobalValue::ExternalLinkage,
- /*Name=*/"powf", mod); // (external, no body)
- func_powf->setCallingConv(CallingConv::C);
-
- Function* func_lit = new Function(
- /*Type=*/FuncTy_3,
- /*Linkage=*/GlobalValue::ExternalLinkage,
- /*Name=*/"lit", mod);
- func_lit->setCallingConv(CallingConv::C);
-
- // Global Variable Declarations
-
-
- // Constant Definitions
- ConstantFP* const_float_4 = ConstantFP::get(Type::FloatTy, APFloat(-1.280000e+02f));
- ConstantFP* const_float_5 = ConstantFP::get(Type::FloatTy, APFloat(1.280000e+02f));
- Constant* const_float_6 = Constant::getNullValue(Type::FloatTy);
- Constant* const_int32_7 = Constant::getNullValue(IntegerType::get(32));
- std::vector<Constant*> const_packed_8_elems;
- ConstantFP* const_float_9 = ConstantFP::get(Type::FloatTy, APFloat(1.000000e+00f));
- const_packed_8_elems.push_back(const_float_9);
- UndefValue* const_float_10 = UndefValue::get(Type::FloatTy);
- const_packed_8_elems.push_back(const_float_10);
- const_packed_8_elems.push_back(const_float_10);
- const_packed_8_elems.push_back(const_float_9);
- Constant* const_packed_8 = ConstantVector::get(VectorTy_2, const_packed_8_elems);
- ConstantInt* const_int32_11 = ConstantInt::get(APInt(32, "1", 10));
- ConstantInt* const_int32_12 = ConstantInt::get(APInt(32, "3", 10));
- ConstantInt* const_int32_13 = ConstantInt::get(APInt(32, "2", 10));
- std::vector<Constant*> const_packed_14_elems;
- const_packed_14_elems.push_back(const_float_9);
- const_packed_14_elems.push_back(const_float_6);
- const_packed_14_elems.push_back(const_float_6);
- const_packed_14_elems.push_back(const_float_9);
- Constant* const_packed_14 = ConstantVector::get(VectorTy_2, const_packed_14_elems);
-
- // Global Variable Definitions
-
- // Function Definitions
-
- // Function: approx (func_approx)
- {
- Function::arg_iterator args = func_approx->arg_begin();
- Value* float_a = args++;
- float_a->setName("a");
- Value* float_b = args++;
- float_b->setName("b");
-
- BasicBlock* label_entry = new BasicBlock("entry",func_approx,0);
-
- // Block entry (label_entry)
- FCmpInst* int1_cmp = new FCmpInst(FCmpInst::FCMP_OLT, float_b, const_float_4, "cmp", label_entry);
- SelectInst* float_b_addr_0 = new SelectInst(int1_cmp, const_float_4, float_b, "b.addr.0", label_entry);
- FCmpInst* int1_cmp3 = new FCmpInst(FCmpInst::FCMP_OGT, float_b_addr_0, const_float_5, "cmp3", label_entry);
- SelectInst* float_b_addr_1 = new SelectInst(int1_cmp3, const_float_5, float_b_addr_0, "b.addr.1", label_entry);
- FCmpInst* int1_cmp7 = new FCmpInst(FCmpInst::FCMP_OLT, float_a, const_float_6, "cmp7", label_entry);
- SelectInst* float_a_addr_0 = new SelectInst(int1_cmp7, const_float_6, float_a, "a.addr.0", label_entry);
- std::vector<Value*> float_call_params;
- float_call_params.push_back(float_a_addr_0);
- float_call_params.push_back(float_b_addr_1);
- CallInst* float_call = new CallInst(func_powf, float_call_params.begin(), float_call_params.end(), "call", label_entry);
- float_call->setCallingConv(CallingConv::C);
- float_call->setTailCall(true);
- new ReturnInst(float_call, label_entry);
- }
-
- // Function: lit (func_lit)
- {
- Function::arg_iterator args = func_lit->arg_begin();
- Value* packed_tmp = args++;
- packed_tmp->setName("tmp");
-
- BasicBlock* label_entry_16 = new BasicBlock("entry",func_lit,0);
- BasicBlock* label_ifthen = new BasicBlock("ifthen",func_lit,0);
- BasicBlock* label_UnifiedReturnBlock = new BasicBlock("UnifiedReturnBlock",func_lit,0);
-
- // Block entry (label_entry_16)
- ExtractElementInst* float_tmp7 = new ExtractElementInst(packed_tmp, const_int32_7, "tmp7", label_entry_16);
- FCmpInst* int1_cmp_17 = new FCmpInst(FCmpInst::FCMP_OGT, float_tmp7, const_float_6, "cmp", label_entry_16);
- new BranchInst(label_ifthen, label_UnifiedReturnBlock, int1_cmp_17, label_entry_16);
-
- // Block ifthen (label_ifthen)
- InsertElementInst* packed_tmp12 = new InsertElementInst(const_packed_8, float_tmp7, const_int32_11, "tmp12", label_ifthen);
- ExtractElementInst* float_tmp14 = new ExtractElementInst(packed_tmp, const_int32_11, "tmp14", label_ifthen);
- ExtractElementInst* float_tmp16 = new ExtractElementInst(packed_tmp, const_int32_12, "tmp16", label_ifthen);
- FCmpInst* int1_cmp_i = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp16, const_float_4, "cmp.i", label_ifthen);
- SelectInst* float_b_addr_0_i = new SelectInst(int1_cmp_i, const_float_4, float_tmp16, "b.addr.0.i", label_ifthen);
- FCmpInst* int1_cmp3_i = new FCmpInst(FCmpInst::FCMP_OGT, float_b_addr_0_i, const_float_5, "cmp3.i", label_ifthen);
- SelectInst* float_b_addr_1_i = new SelectInst(int1_cmp3_i, const_float_5, float_b_addr_0_i, "b.addr.1.i", label_ifthen);
- FCmpInst* int1_cmp7_i = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp14, const_float_6, "cmp7.i", label_ifthen);
- SelectInst* float_a_addr_0_i = new SelectInst(int1_cmp7_i, const_float_6, float_tmp14, "a.addr.0.i", label_ifthen);
- std::vector<Value*> float_call_i_params;
- float_call_i_params.push_back(float_a_addr_0_i);
- float_call_i_params.push_back(float_b_addr_1_i);
- CallInst* float_call_i = new CallInst(func_powf, float_call_i_params.begin(), float_call_i_params.end(), "call.i", label_ifthen);
- float_call_i->setCallingConv(CallingConv::C);
- float_call_i->setTailCall(true);
- InsertElementInst* packed_tmp18 = new InsertElementInst(packed_tmp12, float_call_i, const_int32_13, "tmp18", label_ifthen);
- new ReturnInst(packed_tmp18, label_ifthen);
-
- // Block UnifiedReturnBlock (label_UnifiedReturnBlock)
- new ReturnInst(const_packed_14, label_UnifiedReturnBlock);
-
- }
- return func_lit;
-}
-
void Instructions::ifop(llvm::Value *in)
{
BasicBlock *ifthen = new BasicBlock(name("ifthen"), m_func,0);
@@ -1171,3 +999,4 @@ llvm::Value * Instructions::constVector(float x, float y, float z, float w)
#endif //MESA_LLVM
+
diff --git a/src/mesa/pipe/llvm/llvm_builtins.c b/src/mesa/pipe/llvm/llvm_builtins.c
new file mode 100644
index 0000000000..9d3d6141a6
--- /dev/null
+++ b/src/mesa/pipe/llvm/llvm_builtins.c
@@ -0,0 +1,59 @@
+/*clang --emit-llvm llvm_builtins.c |llvm-as|opt -std-compile-opts|llvm2cpp -gen-contents -o=gallivm_builtins.cpp -f -for=shader -funcname=createGallivmBuiltins*/
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+ /*
+ * Authors:
+ * Zack Rusin zack@tungstengraphics.com
+ */
+typedef __attribute__(( ocu_vector_type(4) )) float float4;
+
+
+extern float powf(float a, float b);
+
+inline float approx(float a, float b)
+{
+ if (b < -128.0f) b = -128.0f;
+ if (b > 128.0f) b = 128.0f;
+ if (a < 0) a = 0;
+ return powf(a, b);
+}
+
+float4 lit(float4 tmp)
+{
+ float4 result;
+ result.x = 1.0;
+ result.w = 1.0;
+ if (tmp.x > 0) {
+ result.y = tmp.x;
+ result.z = approx(tmp.y, tmp.w);
+ } else {
+ result.y = 0;
+ result.z = 0;
+ }
+ return result;
+}