mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-29 08:00:12 +01:00
Align the load/stores. Reduce the amount of debugging output.
This commit is contained in:
parent
6815a9af6c
commit
ba88751716
8 changed files with 660 additions and 968 deletions
|
|
@ -38,6 +38,8 @@
|
|||
#include "pipe/llvm/llvmtgsi.h"
|
||||
#include "pipe/tgsi/exec/tgsi_core.h"
|
||||
|
||||
#define DBG 0
|
||||
|
||||
static INLINE void
|
||||
fetch_attrib4(const void *ptr, unsigned format, float attrib[4])
|
||||
{
|
||||
|
|
@ -155,7 +157,9 @@ void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw)
|
|||
y = vOut->clip[1] = dests[0][1];
|
||||
z = vOut->clip[2] = dests[0][2];
|
||||
w = vOut->clip[3] = dests[0][3];
|
||||
#if DBG
|
||||
printf("output %d: %f %f %f %f\n", 0, x, y, z, w);
|
||||
#endif
|
||||
|
||||
vOut->clipmask = compute_clipmask(vOut->clip, draw->plane, draw->nr_planes);
|
||||
vOut->edgeflag = 1;
|
||||
|
|
@ -183,11 +187,13 @@ void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw)
|
|||
vOut->data[slot][2] = dests[slot][2];
|
||||
vOut->data[slot][3] = dests[slot][3];
|
||||
|
||||
#if DBG
|
||||
printf("output %d: %f %f %f %f\n", slot,
|
||||
vOut->data[slot][0],
|
||||
vOut->data[slot][1],
|
||||
vOut->data[slot][2],
|
||||
vOut->data[slot][3]);
|
||||
#endif
|
||||
}
|
||||
} /* loop over vertices */
|
||||
|
||||
|
|
|
|||
|
|
@ -527,304 +527,6 @@ llvm::Value * Instructions::max(llvm::Value *in1, llvm::Value *in2)
|
|||
return vectorFromVals(selx, sely, selz, selw);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Generated from:
|
||||
extern float exp2f(float x);
|
||||
extern float log2f(float x);
|
||||
|
||||
float4 lit(float4 tmp)
|
||||
{
|
||||
tmp.w = (tmp.w < -128.0) ? -128.0f : ((tmp.w > 128.0f) ? 128.f : tmp.w);
|
||||
float4 result;
|
||||
result.x = 1.0;
|
||||
result.y = tmp.x;
|
||||
result.z = (tmp.x > 0) ? exp2f(tmp.w * log2f(tmp.y)) : 0.0;
|
||||
result.w = 1.0;
|
||||
return result;
|
||||
}
|
||||
with:
|
||||
clang --emit-llvm lit.c |llvm-as|opt -std-compile-opts|llvm2cpp -gen-function -for=lit
|
||||
|
||||
*/
|
||||
Function* makeLitFunction(Module *mod) {
|
||||
|
||||
// Type Definitions
|
||||
ArrayType* ArrayTy_0 = ArrayType::get(IntegerType::get(8), 27);
|
||||
|
||||
PointerType* PointerTy_1 = PointerType::get(ArrayTy_0);
|
||||
|
||||
ArrayType* ArrayTy_2 = ArrayType::get(IntegerType::get(8), 28);
|
||||
|
||||
PointerType* PointerTy_3 = PointerType::get(ArrayTy_2);
|
||||
|
||||
ArrayType* ArrayTy_4 = ArrayType::get(IntegerType::get(8), 8);
|
||||
|
||||
PointerType* PointerTy_5 = PointerType::get(ArrayTy_4);
|
||||
|
||||
ArrayType* ArrayTy_6 = ArrayType::get(IntegerType::get(8), 33);
|
||||
|
||||
PointerType* PointerTy_7 = PointerType::get(ArrayTy_6);
|
||||
|
||||
std::vector<const Type*>FuncTy_8_args;
|
||||
FuncTy_8_args.push_back(Type::FloatTy);
|
||||
FuncTy_8_args.push_back(Type::FloatTy);
|
||||
ParamAttrsList *FuncTy_8_PAL = 0;
|
||||
FunctionType* FuncTy_8 = FunctionType::get(
|
||||
/*Result=*/Type::FloatTy,
|
||||
/*Params=*/FuncTy_8_args,
|
||||
/*isVarArg=*/false,
|
||||
/*ParamAttrs=*/FuncTy_8_PAL);
|
||||
|
||||
std::vector<const Type*>FuncTy_10_args;
|
||||
ParamAttrsList *FuncTy_10_PAL = 0;
|
||||
FunctionType* FuncTy_10 = FunctionType::get(
|
||||
/*Result=*/IntegerType::get(32),
|
||||
/*Params=*/FuncTy_10_args,
|
||||
/*isVarArg=*/true,
|
||||
/*ParamAttrs=*/FuncTy_10_PAL);
|
||||
|
||||
PointerType* PointerTy_9 = PointerType::get(FuncTy_10);
|
||||
|
||||
PointerType* PointerTy_11 = PointerType::get(IntegerType::get(8));
|
||||
|
||||
PointerType* PointerTy_12 = PointerType::get(FuncTy_8);
|
||||
|
||||
VectorType* VectorTy_13 = VectorType::get(Type::FloatTy, 4);
|
||||
|
||||
std::vector<const Type*>FuncTy_14_args;
|
||||
FuncTy_14_args.push_back(VectorTy_13);
|
||||
ParamAttrsList *FuncTy_14_PAL = 0;
|
||||
FunctionType* FuncTy_14 = FunctionType::get(
|
||||
/*Result=*/VectorTy_13,
|
||||
/*Params=*/FuncTy_14_args,
|
||||
/*isVarArg=*/false,
|
||||
/*ParamAttrs=*/FuncTy_14_PAL);
|
||||
|
||||
|
||||
// Function Declarations
|
||||
|
||||
Function* func_approx = new Function(
|
||||
/*Type=*/FuncTy_8,
|
||||
/*Linkage=*/GlobalValue::ExternalLinkage,
|
||||
/*Name=*/"approx", mod);
|
||||
func_approx->setCallingConv(CallingConv::C);
|
||||
|
||||
Function* func_printf = mod->getFunction("printf");
|
||||
|
||||
Function* func_powf = new Function(
|
||||
/*Type=*/FuncTy_8,
|
||||
/*Linkage=*/GlobalValue::ExternalLinkage,
|
||||
/*Name=*/"powf", mod); // (external, no body)
|
||||
func_powf->setCallingConv(CallingConv::C);
|
||||
|
||||
Function* func_lit = new Function(
|
||||
/*Type=*/FuncTy_14,
|
||||
/*Linkage=*/GlobalValue::ExternalLinkage,
|
||||
/*Name=*/"lit", mod);
|
||||
func_lit->setCallingConv(CallingConv::C);
|
||||
|
||||
// Global Variable Declarations
|
||||
|
||||
|
||||
GlobalVariable* gvar_array__str = new GlobalVariable(
|
||||
/*Type=*/ArrayTy_0,
|
||||
/*isConstant=*/true,
|
||||
/*Linkage=*/GlobalValue::InternalLinkage,
|
||||
/*Initializer=*/0, // has initializer, specified below
|
||||
/*Name=*/".str",
|
||||
mod);
|
||||
|
||||
GlobalVariable* gvar_array__str1 = new GlobalVariable(
|
||||
/*Type=*/ArrayTy_2,
|
||||
/*isConstant=*/true,
|
||||
/*Linkage=*/GlobalValue::InternalLinkage,
|
||||
/*Initializer=*/0, // has initializer, specified below
|
||||
/*Name=*/".str1",
|
||||
mod);
|
||||
|
||||
GlobalVariable* gvar_array__str2 = new GlobalVariable(
|
||||
/*Type=*/ArrayTy_4,
|
||||
/*isConstant=*/true,
|
||||
/*Linkage=*/GlobalValue::InternalLinkage,
|
||||
/*Initializer=*/0, // has initializer, specified below
|
||||
/*Name=*/".str2",
|
||||
mod);
|
||||
|
||||
GlobalVariable* gvar_array__str3 = new GlobalVariable(
|
||||
/*Type=*/ArrayTy_6,
|
||||
/*isConstant=*/true,
|
||||
/*Linkage=*/GlobalValue::InternalLinkage,
|
||||
/*Initializer=*/0, // has initializer, specified below
|
||||
/*Name=*/".str3",
|
||||
mod);
|
||||
|
||||
// Constant Definitions
|
||||
Constant* const_array_15 = ConstantArray::get("After test with '%f' '%f'\x0A", true);
|
||||
Constant* const_array_16 = ConstantArray::get("Calling pow with '%f' '%f'\x0A", true);
|
||||
Constant* const_array_17 = ConstantArray::get("IN LIT\x0A", true);
|
||||
Constant* const_array_18 = ConstantArray::get("About to approx with '%f' '%f'\x0A", true);
|
||||
ConstantFP* const_float_19 = ConstantFP::get(Type::FloatTy, APFloat(-1.280000e+02f));
|
||||
ConstantFP* const_float_20 = ConstantFP::get(Type::FloatTy, APFloat(1.280000e+02f));
|
||||
std::vector<Constant*> const_ptr_21_indices;
|
||||
Constant* const_int32_22 = Constant::getNullValue(IntegerType::get(32));
|
||||
const_ptr_21_indices.push_back(const_int32_22);
|
||||
const_ptr_21_indices.push_back(const_int32_22);
|
||||
Constant* const_ptr_21 = ConstantExpr::getGetElementPtr(gvar_array__str, &const_ptr_21_indices[0], const_ptr_21_indices.size() );
|
||||
Constant* const_float_23 = Constant::getNullValue(Type::FloatTy);
|
||||
std::vector<Constant*> const_ptr_24_indices;
|
||||
const_ptr_24_indices.push_back(const_int32_22);
|
||||
const_ptr_24_indices.push_back(const_int32_22);
|
||||
Constant* const_ptr_24 = ConstantExpr::getGetElementPtr(gvar_array__str1, &const_ptr_24_indices[0], const_ptr_24_indices.size() );
|
||||
std::vector<Constant*> const_ptr_25_indices;
|
||||
const_ptr_25_indices.push_back(const_int32_22);
|
||||
const_ptr_25_indices.push_back(const_int32_22);
|
||||
Constant* const_ptr_25 = ConstantExpr::getGetElementPtr(gvar_array__str2, &const_ptr_25_indices[0], const_ptr_25_indices.size() );
|
||||
std::vector<Constant*> const_packed_26_elems;
|
||||
ConstantFP* const_float_27 = ConstantFP::get(Type::FloatTy, APFloat(1.000000e+00f));
|
||||
const_packed_26_elems.push_back(const_float_27);
|
||||
UndefValue* const_float_28 = UndefValue::get(Type::FloatTy);
|
||||
const_packed_26_elems.push_back(const_float_28);
|
||||
const_packed_26_elems.push_back(const_float_28);
|
||||
const_packed_26_elems.push_back(const_float_27);
|
||||
Constant* const_packed_26 = ConstantVector::get(VectorTy_13, const_packed_26_elems);
|
||||
ConstantInt* const_int32_29 = ConstantInt::get(APInt(32, "1", 10));
|
||||
ConstantInt* const_int32_30 = ConstantInt::get(APInt(32, "3", 10));
|
||||
std::vector<Constant*> const_ptr_31_indices;
|
||||
const_ptr_31_indices.push_back(const_int32_22);
|
||||
const_ptr_31_indices.push_back(const_int32_22);
|
||||
Constant* const_ptr_31 = ConstantExpr::getGetElementPtr(gvar_array__str3, &const_ptr_31_indices[0], const_ptr_31_indices.size() );
|
||||
ConstantInt* const_int32_32 = ConstantInt::get(APInt(32, "2", 10));
|
||||
std::vector<Constant*> const_packed_33_elems;
|
||||
const_packed_33_elems.push_back(const_float_27);
|
||||
const_packed_33_elems.push_back(const_float_23);
|
||||
const_packed_33_elems.push_back(const_float_23);
|
||||
const_packed_33_elems.push_back(const_float_27);
|
||||
Constant* const_packed_33 = ConstantVector::get(VectorTy_13, const_packed_33_elems);
|
||||
|
||||
// Global Variable Definitions
|
||||
gvar_array__str->setInitializer(const_array_15);
|
||||
gvar_array__str1->setInitializer(const_array_16);
|
||||
gvar_array__str2->setInitializer(const_array_17);
|
||||
gvar_array__str3->setInitializer(const_array_18);
|
||||
|
||||
// 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_19, "cmp", label_entry);
|
||||
SelectInst* float_b_addr_0 = new SelectInst(int1_cmp, const_float_19, float_b, "b.addr.0", label_entry);
|
||||
FCmpInst* int1_cmp3 = new FCmpInst(FCmpInst::FCMP_OGT, float_b_addr_0, const_float_20, "cmp3", label_entry);
|
||||
SelectInst* float_b_addr_1 = new SelectInst(int1_cmp3, const_float_20, float_b_addr_0, "b.addr.1", label_entry);
|
||||
CastInst* double_conv = new FPExtInst(float_a, Type::DoubleTy, "conv", label_entry);
|
||||
CastInst* double_conv8 = new FPExtInst(float_b_addr_1, Type::DoubleTy, "conv8", label_entry);
|
||||
std::vector<Value*> int32_call_params;
|
||||
int32_call_params.push_back(const_ptr_21);
|
||||
int32_call_params.push_back(double_conv);
|
||||
int32_call_params.push_back(double_conv8);
|
||||
CallInst* int32_call = new CallInst(func_printf, int32_call_params.begin(), int32_call_params.end(), "call", label_entry);
|
||||
int32_call->setCallingConv(CallingConv::C);
|
||||
int32_call->setTailCall(true);
|
||||
FCmpInst* int1_cmp11 = new FCmpInst(FCmpInst::FCMP_OLT, float_a, const_float_23, "cmp11", label_entry);
|
||||
SelectInst* float_a_addr_0 = new SelectInst(int1_cmp11, const_float_23, float_a, "a.addr.0", label_entry);
|
||||
CastInst* double_conv16 = new FPExtInst(float_a_addr_0, Type::DoubleTy, "conv16", label_entry);
|
||||
std::vector<Value*> int32_call19_params;
|
||||
int32_call19_params.push_back(const_ptr_24);
|
||||
int32_call19_params.push_back(double_conv16);
|
||||
int32_call19_params.push_back(double_conv8);
|
||||
CallInst* int32_call19 = new CallInst(func_printf, int32_call19_params.begin(), int32_call19_params.end(), "call19", label_entry);
|
||||
int32_call19->setCallingConv(CallingConv::C);
|
||||
int32_call19->setTailCall(true);
|
||||
std::vector<Value*> float_call22_params;
|
||||
float_call22_params.push_back(float_a_addr_0);
|
||||
float_call22_params.push_back(float_b_addr_1);
|
||||
CallInst* float_call22 = new CallInst(func_powf, float_call22_params.begin(), float_call22_params.end(), "call22", label_entry);
|
||||
float_call22->setCallingConv(CallingConv::C);
|
||||
float_call22->setTailCall(true);
|
||||
new ReturnInst(float_call22, 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_35 = 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_35)
|
||||
CallInst* int32_call_36 = new CallInst(func_printf, const_ptr_25, "call", label_entry_35);
|
||||
int32_call_36->setCallingConv(CallingConv::C);
|
||||
int32_call_36->setTailCall(true);
|
||||
ExtractElementInst* float_tmp7 = new ExtractElementInst(packed_tmp, const_int32_22, "tmp7", label_entry_35);
|
||||
FCmpInst* int1_cmp_37 = new FCmpInst(FCmpInst::FCMP_OGT, float_tmp7, const_float_23, "cmp", label_entry_35);
|
||||
new BranchInst(label_ifthen, label_UnifiedReturnBlock, int1_cmp_37, label_entry_35);
|
||||
|
||||
// Block ifthen (label_ifthen)
|
||||
InsertElementInst* packed_tmp12 = new InsertElementInst(const_packed_26, float_tmp7, const_int32_29, "tmp12", label_ifthen);
|
||||
ExtractElementInst* float_tmp14 = new ExtractElementInst(packed_tmp, const_int32_29, "tmp14", label_ifthen);
|
||||
CastInst* double_conv15 = new FPExtInst(float_tmp14, Type::DoubleTy, "conv15", label_ifthen);
|
||||
ExtractElementInst* float_tmp17 = new ExtractElementInst(packed_tmp, const_int32_30, "tmp17", label_ifthen);
|
||||
CastInst* double_conv18 = new FPExtInst(float_tmp17, Type::DoubleTy, "conv18", label_ifthen);
|
||||
std::vector<Value*> int32_call19_39_params;
|
||||
int32_call19_39_params.push_back(const_ptr_31);
|
||||
int32_call19_39_params.push_back(double_conv15);
|
||||
int32_call19_39_params.push_back(double_conv18);
|
||||
CallInst* int32_call19_39 = new CallInst(func_printf, int32_call19_39_params.begin(), int32_call19_39_params.end(), "call19", label_ifthen);
|
||||
int32_call19_39->setCallingConv(CallingConv::C);
|
||||
int32_call19_39->setTailCall(true);
|
||||
FCmpInst* int1_cmp_i = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp17, const_float_19, "cmp.i", label_ifthen);
|
||||
SelectInst* float_b_addr_0_i = new SelectInst(int1_cmp_i, const_float_19, float_tmp17, "b.addr.0.i", label_ifthen);
|
||||
FCmpInst* int1_cmp3_i = new FCmpInst(FCmpInst::FCMP_OGT, float_b_addr_0_i, const_float_20, "cmp3.i", label_ifthen);
|
||||
SelectInst* float_b_addr_1_i = new SelectInst(int1_cmp3_i, const_float_20, float_b_addr_0_i, "b.addr.1.i", label_ifthen);
|
||||
CastInst* double_conv8_i = new FPExtInst(float_b_addr_1_i, Type::DoubleTy, "conv8.i", label_ifthen);
|
||||
std::vector<Value*> int32_call_i_params;
|
||||
int32_call_i_params.push_back(const_ptr_21);
|
||||
int32_call_i_params.push_back(double_conv15);
|
||||
int32_call_i_params.push_back(double_conv8_i);
|
||||
CallInst* int32_call_i = new CallInst(func_printf, int32_call_i_params.begin(), int32_call_i_params.end(), "call.i", label_ifthen);
|
||||
int32_call_i->setCallingConv(CallingConv::C);
|
||||
int32_call_i->setTailCall(true);
|
||||
FCmpInst* int1_cmp11_i = new FCmpInst(FCmpInst::FCMP_OLT, float_tmp14, const_float_23, "cmp11.i", label_ifthen);
|
||||
SelectInst* float_a_addr_0_i = new SelectInst(int1_cmp11_i, const_float_23, float_tmp14, "a.addr.0.i", label_ifthen);
|
||||
CastInst* double_conv16_i = new FPExtInst(float_a_addr_0_i, Type::DoubleTy, "conv16.i", label_ifthen);
|
||||
std::vector<Value*> int32_call19_i_params;
|
||||
int32_call19_i_params.push_back(const_ptr_24);
|
||||
int32_call19_i_params.push_back(double_conv16_i);
|
||||
int32_call19_i_params.push_back(double_conv8_i);
|
||||
CallInst* int32_call19_i = new CallInst(func_printf, int32_call19_i_params.begin(), int32_call19_i_params.end(), "call19.i", label_ifthen);
|
||||
int32_call19_i->setCallingConv(CallingConv::C);
|
||||
int32_call19_i->setTailCall(true);
|
||||
std::vector<Value*> float_call22_i_params;
|
||||
float_call22_i_params.push_back(float_a_addr_0_i);
|
||||
float_call22_i_params.push_back(float_b_addr_1_i);
|
||||
CallInst* float_call22_i = new CallInst(func_powf, float_call22_i_params.begin(), float_call22_i_params.end(), "call22.i", label_ifthen);
|
||||
float_call22_i->setCallingConv(CallingConv::C);
|
||||
float_call22_i->setTailCall(true);
|
||||
InsertElementInst* packed_tmp26 = new InsertElementInst(packed_tmp12, float_call22_i, const_int32_32, "tmp26", label_ifthen);
|
||||
new ReturnInst(packed_tmp26, label_ifthen);
|
||||
|
||||
// Block UnifiedReturnBlock (label_UnifiedReturnBlock)
|
||||
new ReturnInst(const_packed_33, label_UnifiedReturnBlock);
|
||||
|
||||
}
|
||||
|
||||
return func_lit;
|
||||
|
||||
}
|
||||
|
||||
void Instructions::printVector(llvm::Value *val)
|
||||
{
|
||||
static const char *frmt = "Vector is [%f, %f, %f, %f]\x0A";
|
||||
|
|
@ -850,6 +552,9 @@ void Instructions::printVector(llvm::Value *val)
|
|||
}
|
||||
|
||||
Function *func_printf = m_mod->getFunction("printf");
|
||||
if (!func_printf)
|
||||
func_printf = declarePrintf();
|
||||
assert(func_printf);
|
||||
ExtractElementInst *x = new ExtractElementInst(val, unsigned(0),
|
||||
name("extractx"),
|
||||
m_block);
|
||||
|
|
@ -872,7 +577,201 @@ void Instructions::printVector(llvm::Value *val)
|
|||
params.push_back(dy);
|
||||
params.push_back(dz);
|
||||
params.push_back(dw);
|
||||
CallInst* call = new CallInst(func_printf, params.begin(), params.end(), "printf", m_block);
|
||||
CallInst* call = new CallInst(func_printf, params.begin(), params.end(),
|
||||
name("printf"), m_block);
|
||||
call->setCallingConv(CallingConv::C);
|
||||
call->setTailCall(true);
|
||||
}
|
||||
|
||||
llvm::Function * Instructions::declarePrintf()
|
||||
{
|
||||
std::vector<const Type*> args;
|
||||
ParamAttrsList *params = 0;
|
||||
FunctionType* funcTy = FunctionType::get(
|
||||
/*Result=*/IntegerType::get(32),
|
||||
/*Params=*/args,
|
||||
/*isVarArg=*/true,
|
||||
/*ParamAttrs=*/params);
|
||||
Function* func_printf = new Function(
|
||||
/*Type=*/funcTy,
|
||||
/*Linkage=*/GlobalValue::ExternalLinkage,
|
||||
/*Name=*/"printf", m_mod);
|
||||
func_printf->setCallingConv(CallingConv::C);
|
||||
return func_printf;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
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);
|
||||
|
||||
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 func_lit;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ private:
|
|||
|
||||
llvm::Value *vectorFromVals(llvm::Value *x, llvm::Value *y,
|
||||
llvm::Value *z, llvm::Value *w=0);
|
||||
|
||||
llvm::Function *declarePrintf();
|
||||
private:
|
||||
llvm::Module *m_mod;
|
||||
llvm::Function *m_func;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -102,7 +102,6 @@ void from_array(float4 (*res)[16], float (*ainputs)[16][4],
|
|||
vec.y = ainputs[i][j][1];
|
||||
vec.z = ainputs[i][j][2];
|
||||
vec.w = ainputs[i][j][3];
|
||||
printf("FRA(%d %d) %f %f %f %f\n", i, j, vec.x, vec.y, vec.z, vec.w);
|
||||
res[i][j] = vec;
|
||||
}
|
||||
}
|
||||
|
|
@ -117,7 +116,6 @@ void from_consts(float4 *res, float (*ainputs)[4],
|
|||
vec.y = ainputs[i][1];
|
||||
vec.z = ainputs[i][2];
|
||||
vec.w = ainputs[i][3];
|
||||
printf("VCONST(%d) %f %f %f %f\n", i, vec.x, vec.y, vec.z, vec.w);
|
||||
res[i] = vec;
|
||||
}
|
||||
}
|
||||
|
|
@ -127,7 +125,6 @@ void to_array(float (*dests)[4], float4 *in, int num_attribs)
|
|||
for (int i = 0; i < num_attribs; ++i) {
|
||||
float *rd = dests[i];
|
||||
float4 ri = in[i];
|
||||
printf("DEST = %f %f %f %f\n", ri.x, ri.y, ri.z, ri.w);
|
||||
rd[0] = ri.x;
|
||||
rd[1] = ri.y;
|
||||
rd[2] = ri.z;
|
||||
|
|
@ -135,8 +132,8 @@ void to_array(float (*dests)[4], float4 *in, int num_attribs)
|
|||
}
|
||||
}
|
||||
|
||||
extern void execute_shader(float4 *dests, float4 *inputs,
|
||||
float4 *consts);
|
||||
extern void execute_shader(float4 dests[16], float4 inputs[16],
|
||||
float4 consts[32]);
|
||||
|
||||
void run_vertex_shader(float (*ainputs)[16][4],
|
||||
float (*dests)[16][4],
|
||||
|
|
@ -150,16 +147,14 @@ void run_vertex_shader(float (*ainputs)[16][4],
|
|||
float4 consts[32];
|
||||
float4 results[16*32*4][16];
|
||||
|
||||
printf("XXX LLVM run_vertex_shader vertices = %d, inputs = %d, consts = %d\n",
|
||||
num_vertices, num_inputs, num_consts);
|
||||
/*printf("XXX LLVM run_vertex_shader vertices = %d, inputs = %d, attribs = %d, consts = %d\n",
|
||||
num_vertices, num_inputs, num_attribs, num_consts);*/
|
||||
from_array(inputs, ainputs, num_vertices, num_inputs);
|
||||
from_consts(consts, aconsts, num_consts);
|
||||
printf(" after conversion\n");
|
||||
for (int i = 0; i < num_vertices; ++i) {
|
||||
float4 *in = inputs[i];
|
||||
float4 *res = results[i];
|
||||
execute_shader(res, in, consts);
|
||||
printf("after executing shader\n");
|
||||
to_array(dests[i], res, num_attribs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,17 @@
|
|||
#include <llvm/Analysis/LoopPass.h>
|
||||
#include <llvm/Target/TargetData.h>
|
||||
#include <llvm/Bitcode/ReaderWriter.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace llvm;
|
||||
#include "llvm_base_shader.cpp"
|
||||
|
||||
|
||||
static int GLOBAL_ID = 0;
|
||||
|
||||
static inline void addPass(PassManager &PM, Pass *P) {
|
||||
// Add the pass to the pass manager...
|
||||
PM.add(P);
|
||||
|
|
@ -168,8 +173,8 @@ translate_instruction(llvm::Module *module,
|
|||
inputs[i] = val;
|
||||
}
|
||||
|
||||
if (inputs[0])
|
||||
instr->printVector(inputs[0]);
|
||||
/*if (inputs[0])
|
||||
instr->printVector(inputs[0]);*/
|
||||
llvm::Value *out = 0;
|
||||
printf("Opcode is %d\n", inst->Instruction.Opcode);
|
||||
switch (inst->Instruction.Opcode) {
|
||||
|
|
@ -523,7 +528,6 @@ translate_instruction(llvm::Module *module,
|
|||
printf("translate instr END\n");
|
||||
}
|
||||
|
||||
|
||||
static llvm::Module *
|
||||
tgsi_to_llvm(struct ga_llvm_prog *prog, const struct tgsi_token *tokens)
|
||||
{
|
||||
|
|
@ -533,7 +537,11 @@ tgsi_to_llvm(struct ga_llvm_prog *prog, const struct tgsi_token *tokens)
|
|||
struct tgsi_full_declaration fd;
|
||||
|
||||
Function* shader = mod->getFunction("execute_shader");
|
||||
shader->setName("execute_shader_2");
|
||||
std::ostringstream stream;
|
||||
stream << "execute_shader";
|
||||
stream << prog->id;
|
||||
std::string func_name = stream.str();
|
||||
shader->setName(func_name.c_str());
|
||||
|
||||
Function::arg_iterator args = shader->arg_begin();
|
||||
Value *ptr_OUT = args++;
|
||||
|
|
@ -593,8 +601,10 @@ struct ga_llvm_prog *
|
|||
ga_llvm_from_tgsi(struct pipe_context *pipe, const struct tgsi_token *tokens)
|
||||
{
|
||||
std::cout << "Creating llvm from: " <<std::endl;
|
||||
++GLOBAL_ID;
|
||||
struct ga_llvm_prog *ga_llvm =
|
||||
(struct ga_llvm_prog *)malloc(sizeof(struct ga_llvm_prog));
|
||||
ga_llvm->id = GLOBAL_ID;
|
||||
fprintf(stderr, "----- TGSI Start ---- \n");
|
||||
tgsi_dump(tokens, 0);
|
||||
fprintf(stderr, "----- TGSI End ---- \n");
|
||||
|
|
@ -618,9 +628,7 @@ ga_llvm_from_tgsi(struct pipe_context *pipe, const struct tgsi_token *tokens)
|
|||
ga_llvm->module = mod;
|
||||
|
||||
Function *func = mod->getFunction("run_vertex_shader");
|
||||
std::cout << "run_vertex_shader = "<<func<<std::endl;
|
||||
ga_llvm->function = ee->getPointerToFunctionOrStub(func);
|
||||
std::cout << " -- FUNC is " <<ga_llvm->function<<std::endl;
|
||||
|
||||
return ga_llvm;
|
||||
}
|
||||
|
|
@ -651,12 +659,9 @@ int ga_llvm_prog_exec(struct ga_llvm_prog *prog,
|
|||
int num_inputs,
|
||||
int num_attribs)
|
||||
{
|
||||
std::cout << "---- START LLVM Execution "<<std::endl;
|
||||
vertex_shader_runner runner = reinterpret_cast<vertex_shader_runner>(prog->function);
|
||||
runner(inputs, dests, consts, num_vertices, num_inputs,
|
||||
num_attribs, prog->num_consts);
|
||||
|
||||
std::cout << "---- END LLVM Execution "<<std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ struct ga_llvm_prog {
|
|||
void *engine;
|
||||
void *function;
|
||||
int num_consts;
|
||||
int id;
|
||||
};
|
||||
struct ga_llvm_prog *
|
||||
ga_llvm_from_tgsi(struct pipe_context *pipe, const struct tgsi_token *tokens);
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ llvm::Value *Storage::inputElement(int idx)
|
|||
m_block);
|
||||
LoadInst *load = new LoadInst(getElem, name("input"),
|
||||
false, m_block);
|
||||
load->setAlignment(8);
|
||||
m_inputs[idx] = load;
|
||||
return load;
|
||||
}
|
||||
|
|
@ -93,6 +94,7 @@ llvm::Value *Storage::constElement(int idx)
|
|||
m_block);
|
||||
LoadInst *load = new LoadInst(getElem, name("const"),
|
||||
false, m_block);
|
||||
load->setAlignment(8);
|
||||
m_consts[idx] = load;
|
||||
return load;
|
||||
}
|
||||
|
|
@ -136,6 +138,7 @@ void Storage::store(int dstIdx, llvm::Value *val, int mask)
|
|||
name("out_ptr"),
|
||||
m_block);
|
||||
StoreInst *st = new StoreInst(val, getElem, false, m_block);
|
||||
st->setAlignment(8);
|
||||
//m_dstCache[dstIdx] = st;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue