From 1edb45bbf0ef831e90bab50fe84a3e800ce4229a Mon Sep 17 00:00:00 2001 From: Junyan He Date: Tue, 10 Jun 2014 12:52:37 +0800 Subject: [PATCH] Add two special register for printf output buffer usage printfiptr for printf index buffer pointer in curbe and printfbptr for printf output buffer pointer in curbe. Signed-off-by: Junyan He Reviewed-by: Zhigang Gong --- backend/src/backend/gen_context.cpp | 2 ++ backend/src/backend/program.h | 2 ++ backend/src/ir/profile.cpp | 5 ++++- backend/src/ir/profile.hpp | 4 +++- backend/src/llvm/llvm_gen_backend.cpp | 11 +++++++++++ backend/src/llvm/llvm_gen_ocl_function.hxx | 5 +++++ backend/src/ocl_stdlib.tmpl.h | 5 +++++ 7 files changed, 32 insertions(+), 2 deletions(-) diff --git a/backend/src/backend/gen_context.cpp b/backend/src/backend/gen_context.cpp index 7133261..b718b20 100644 --- a/backend/src/backend/gen_context.cpp +++ b/backend/src/backend/gen_context.cpp @@ -1842,6 +1842,8 @@ namespace gbe INSERT_REG(numgroup1, GROUP_NUM_Y) INSERT_REG(numgroup2, GROUP_NUM_Z) INSERT_REG(stackptr, STACK_POINTER) + INSERT_REG(printfbptr, PRINTF_BUF_POINTER); + INSERT_REG(printfiptr, PRINTF_INDEX_POINTER); do {} while(0); } }); diff --git a/backend/src/backend/program.h b/backend/src/backend/program.h index 5c72964..ad018e8 100644 --- a/backend/src/backend/program.h +++ b/backend/src/backend/program.h @@ -72,6 +72,8 @@ enum gbe_curbe_type { GBE_CURBE_WORK_DIM, GBE_CURBE_IMAGE_INFO, GBE_CURBE_STACK_POINTER, + GBE_CURBE_PRINTF_BUF_POINTER, + GBE_CURBE_PRINTF_INDEX_POINTER, GBE_CURBE_KERNEL_ARGUMENT, GBE_CURBE_EXTRA_ARGUMENT, GBE_CURBE_BLOCK_IP, diff --git a/backend/src/ir/profile.cpp b/backend/src/ir/profile.cpp index d583df9..a58bbd7 100644 --- a/backend/src/ir/profile.cpp +++ b/backend/src/ir/profile.cpp @@ -41,7 +41,8 @@ namespace ir { "block_ip", "barrier_id", "thread_number", "work_dimension", "zero", "one", - "retVal", "slm_offset" + "retVal", "slm_offset", + "printf_buffer_pointer", "printf_index_buffer_pointer" }; #if GBE_DEBUG @@ -82,6 +83,8 @@ namespace ir { DECL_NEW_REG(FAMILY_DWORD, one, 1); DECL_NEW_REG(FAMILY_WORD, retVal, 1); DECL_NEW_REG(FAMILY_WORD, slmoffset, 1); + DECL_NEW_REG(FAMILY_DWORD, printfbptr, 1); + DECL_NEW_REG(FAMILY_DWORD, printfiptr, 1); } #undef DECL_NEW_REG diff --git a/backend/src/ir/profile.hpp b/backend/src/ir/profile.hpp index 4a8062b..c15a792 100644 --- a/backend/src/ir/profile.hpp +++ b/backend/src/ir/profile.hpp @@ -69,7 +69,9 @@ namespace ir { static const Register one = Register(25); // scalar register holds one. static const Register retVal = Register(26); // helper register to do data flow analysis. static const Register slmoffset = Register(27); // Group's SLM offset in total 64K SLM - static const uint32_t regNum = 28; // number of special registers + static const Register printfbptr = Register(28); // printf buffer address . + static const Register printfiptr = Register(29); // printf index buffer address. + static const uint32_t regNum = 30; // number of special registers extern const char *specialRegMean[]; // special register name. } /* namespace ocl */ diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index db9e73c..7802818 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -2238,6 +2238,10 @@ namespace gbe regTranslator.newScalarProxy(ir::ocl::goffset2, dst); break; case GEN_OCL_GET_WORK_DIM: regTranslator.newScalarProxy(ir::ocl::workdim, dst); break; + case GEN_OCL_PRINTF_BUF_ADDR: + regTranslator.newScalarProxy(ir::ocl::printfbptr, dst); break; + case GEN_OCL_PRINTF_INDEX_BUF_ADDR: + regTranslator.newScalarProxy(ir::ocl::printfiptr, dst); break; case GEN_OCL_FBH: case GEN_OCL_FBL: case GEN_OCL_COS: @@ -2384,6 +2388,8 @@ namespace gbe case GEN_OCL_SIMD_ALL: this->newRegister(&I); break; + case GEN_OCL_PRINTF: + break; default: GBE_ASSERTM(false, "Function call are not supported yet"); }; @@ -2962,6 +2968,11 @@ namespace gbe ctx.F32TO16(ir::TYPE_U16, ir::TYPE_FLOAT, getRegister(&I), getRegister(I.getOperand(0))); break; #undef DEF + + case GEN_OCL_PRINTF: + break; + case GEN_OCL_PRINTF_BUF_ADDR: + case GEN_OCL_PRINTF_INDEX_BUF_ADDR: default: break; } } diff --git a/backend/src/llvm/llvm_gen_ocl_function.hxx b/backend/src/llvm/llvm_gen_ocl_function.hxx index 4236298..a74803b 100644 --- a/backend/src/llvm/llvm_gen_ocl_function.hxx +++ b/backend/src/llvm/llvm_gen_ocl_function.hxx @@ -179,3 +179,8 @@ DECL_LLVM_GEN_FUNCTION(CONV_F32_TO_F16, __gen_ocl_f32to16) // SIMD level function for internal usage DECL_LLVM_GEN_FUNCTION(SIMD_ANY, __gen_ocl_simd_any) DECL_LLVM_GEN_FUNCTION(SIMD_ALL, __gen_ocl_simd_all) + +// printf function +DECL_LLVM_GEN_FUNCTION(PRINTF, __gen_ocl_printf) +DECL_LLVM_GEN_FUNCTION(PRINTF_BUF_ADDR, __gen_ocl_printf_get_buf_addr) +DECL_LLVM_GEN_FUNCTION(PRINTF_INDEX_BUF_ADDR, __gen_ocl_printf_get_index_buf_addr) diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index 01bb337..6fab974 100755 --- a/backend/src/ocl_stdlib.tmpl.h +++ b/backend/src/ocl_stdlib.tmpl.h @@ -4953,4 +4953,9 @@ INLINE_OVERLOADABLE float __gen_ocl_internal_fastpath_tanh (float x) #undef CONST #undef OVERLOADABLE #undef INLINE + +/* The printf function. */ +int __gen_ocl_printf_stub(const char * format, ...); +#define printf __gen_ocl_printf_stub + #endif /* __GEN_OCL_STDLIB_H__ */ -- 2.7.4