[Beignet] [PATCH] GBE: Fix the printf issue caused by new bti implementation

Ruiling Song ruiling.song at intel.com
Wed Dec 3 22:24:44 PST 2014


The new bti implementation does not deal with printf internal buffer specially.
Which cause printf print nothing! But I think it is better to declare the
internal buffer for printf in global memory space instead of private space.
Then the bti implementation don't have to deal with it specially.

Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
 backend/src/llvm/llvm_printf_parser.cpp |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp
index 11e9633..8fec683 100644
--- a/backend/src/llvm/llvm_printf_parser.cpp
+++ b/backend/src/llvm/llvm_printf_parser.cpp
@@ -617,13 +617,25 @@ error:
 
     if (!pbuf_ptr) {
       /* alloc a new buffer ptr to collect the print output. */
-      Type *ptrTy = Type::getInt32PtrTy(module->getContext());
-      llvm::Constant * pBuf = module->getOrInsertGlobal(StringRef("__gen_ocl_printf_buf"), ptrTy);
+      Type *ptrTy = Type::getInt32PtrTy(module->getContext(), 1);
+      llvm::Constant *pBuf = new GlobalVariable(*module, ptrTy, false,
+                                GlobalVariable::ExternalLinkage,
+                                nullptr,
+                                StringRef("__gen_ocl_printf_buf"),
+                                nullptr,
+                                GlobalVariable::NotThreadLocal,
+                                1);
       pbuf_ptr = builder->CreatePtrToInt(pBuf, Type::getInt32Ty(module->getContext()));
     }
     if (!index_buf_ptr) {
-      Type *ptrTy = Type::getInt32PtrTy(module->getContext());
-      llvm::Constant * pBuf = module->getOrInsertGlobal(StringRef("__gen_ocl_printf_index_buf"), ptrTy);
+      Type *ptrTy = Type::getInt32PtrTy(module->getContext(), 1);
+      llvm::Constant *pBuf = new GlobalVariable(*module, ptrTy, false,
+                                GlobalVariable::ExternalLinkage,
+                                nullptr,
+                                StringRef("__gen_ocl_printf_index_buf"),
+                                nullptr,
+                                GlobalVariable::NotThreadLocal,
+                                1);
       index_buf_ptr = builder->CreatePtrToInt(pBuf, Type::getInt32Ty(module->getContext()));
     }
 
-- 
1.7.10.4



More information about the Beignet mailing list