[Beignet] [PATCH 3/4] SPIR binary support for printf function.
xionghu.luo at intel.com
xionghu.luo at intel.com
Sun Mar 8 20:24:27 PDT 2015
From: Luo Xionghu <xionghu.luo at intel.com>
rename "printf" to "__gen_ocl_printf_stub" and "puts" to
"__gen_ocl_puts_stub" in PrintfParser after link.
Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
backend/src/libocl/include/ocl_printf.h | 3 +++
backend/src/llvm/llvm_printf_parser.cpp | 12 ++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/backend/src/libocl/include/ocl_printf.h b/backend/src/libocl/include/ocl_printf.h
index ffeefb9..27cef27 100644
--- a/backend/src/libocl/include/ocl_printf.h
+++ b/backend/src/libocl/include/ocl_printf.h
@@ -24,9 +24,12 @@
/* From LLVM 3.4, c string are all in constant address space */
#if 100*__clang_major__ + __clang_minor__ < 304
int __gen_ocl_printf_stub(const char * format, ...);
+int __gen_ocl_puts_stub(const char * format);
#else
int __gen_ocl_printf_stub(constant char * format, ...);
+int __gen_ocl_puts_stub(constant char * format);
#endif
#define printf __gen_ocl_printf_stub
+#define puts __gen_ocl_puts_stub
#endif
diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp
index 9632011..7800c01 100644
--- a/backend/src/llvm/llvm_printf_parser.cpp
+++ b/backend/src/llvm/llvm_printf_parser.cpp
@@ -552,7 +552,6 @@ error:
return true;
}
-
bool PrintfParser::runOnFunction(llvm::Function &F)
{
bool changed = false;
@@ -583,6 +582,15 @@ error:
builder = new IRBuilder<>(module->getContext());
+ llvm::GlobalValue* gFun = module->getNamedValue("printf");
+ if(gFun) {
+ gFun->setName("__gen_ocl_printf_stub");
+ }
+ llvm::GlobalValue* gFun2 = module->getNamedValue("puts");
+ if(gFun2 ) {
+ gFun2->setName("__gen_ocl_puts_stub");
+ }
+
/* First find printfs and caculate all slots size of one loop. */
for (llvm::Function::iterator B = F.begin(), BE = F.end(); B != BE; B++) {
for (BasicBlock::iterator instI = B->begin(),
@@ -602,7 +610,7 @@ error:
Value *Callee = call->getCalledValue();
const std::string fnName = Callee->getName();
- if (fnName != "__gen_ocl_printf_stub")
+ if (fnName != "__gen_ocl_printf_stub" && fnName != "__gen_ocl_puts_stub")
continue;
if (!parseOnePrintfInstruction(call, pInfo, sizeof_size)) {
--
1.9.1
More information about the Beignet
mailing list