[Beignet] [PATCH 14/18] Backend: Add parameter source to all the build functions.

junyan.he at inbox.com junyan.he at inbox.com
Thu Dec 24 03:02:06 PST 2015


From: Junyan He <junyan.he at linux.intel.com>

We need to pass down the source code string in order to
output profiling in source code.

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/src/backend/gen_program.cpp   |  7 ++++---
 backend/src/backend/program.cpp       | 10 +++++-----
 backend/src/backend/program.h         |  3 ++-
 backend/src/backend/program.hpp       |  2 +-
 backend/src/llvm/llvm_gen_backend.hpp |  2 +-
 backend/src/llvm/llvm_profiling.cpp   | 14 +++++++++-----
 backend/src/llvm/llvm_to_gen.cpp      |  4 ++--
 backend/src/llvm/llvm_to_gen.hpp      |  2 +-
 src/cl_program.c                      |  3 ++-
 9 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 48159e5..dd6fe0f 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -406,7 +406,8 @@ namespace gbe {
                                            char *err,
                                            size_t *errSize,
                                            int optLevel,
-                                           const char* options)
+                                           const char* options,
+                                           const char* source)
   {
     using namespace gbe;
     uint32_t fast_relaxed_math = 0;
@@ -418,7 +419,7 @@ namespace gbe {
 #ifdef GBE_COMPILER_AVAILABLE
     std::string error;
     // Try to compile the program
-    if (program->buildFromLLVMFile(fileName, module, error, optLevel) == false) {
+    if (program->buildFromLLVMFile(fileName, module, error, optLevel, source) == false) {
       if (err != NULL && errSize != NULL && stringSize > 0u) {
         const size_t msgSize = std::min(error.size(), stringSize-1u);
         std::memcpy(err, error.c_str(), msgSize);
@@ -528,7 +529,7 @@ namespace gbe {
     acquireLLVMContextLock();
     llvm::Module* module = (llvm::Module*)p->module;
 
-    if (p->buildFromLLVMFile(NULL, module, error, optLevel) == false) {
+    if (p->buildFromLLVMFile(NULL, module, error, optLevel, NULL) == false) {
       if (err != NULL && errSize != NULL && stringSize > 0u) {
         const size_t msgSize = std::min(error.size(), stringSize-1u);
         std::memcpy(err, error.c_str(), msgSize);
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index b65124a..06d5f6b 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -119,7 +119,7 @@ namespace gbe {
   IVAR(OCL_PROFILING_LOG, 0, 0, 1); // Int for different profiling types.
   BVAR(OCL_OUTPUT_BUILD_LOG, false);
 
-  bool Program::buildFromLLVMFile(const char *fileName, const void* module, std::string &error, int optLevel) {
+  bool Program::buildFromLLVMFile(const char *fileName, const void* module, std::string &error, int optLevel, const char* source) {
     ir::Unit *unit = new ir::Unit();
     llvm::Module * cloned_module = NULL;
     bool ret = true;
@@ -129,7 +129,7 @@ namespace gbe {
     bool strictMath = true;
     if (fast_relaxed_math || !OCL_STRICT_CONFORMANCE)
       strictMath = false;
-    if (llvmToGen(*unit, fileName, module, optLevel, strictMath, OCL_PROFILING_LOG) == false) {
+    if (llvmToGen(*unit, fileName, module, optLevel, strictMath, OCL_PROFILING_LOG, source) == false) {
       if (fileName)
         error = std::string(fileName) + " not found";
       delete unit;
@@ -142,10 +142,10 @@ namespace gbe {
       unit = new ir::Unit();
       if(cloned_module){
         //suppose file exists and llvmToGen will not return false.
-        llvmToGen(*unit, fileName, cloned_module, 0, strictMath, OCL_PROFILING_LOG);
+        llvmToGen(*unit, fileName, cloned_module, 0, strictMath, OCL_PROFILING_LOG, source);
       }else{
         //suppose file exists and llvmToGen will not return false.
-        llvmToGen(*unit, fileName, module, 0, strictMath, OCL_PROFILING_LOG);
+        llvmToGen(*unit, fileName, module, 0, strictMath, OCL_PROFILING_LOG, source);
       }
     }
     assert(unit->getValid());
@@ -893,7 +893,7 @@ BVAR(OCL_DEBUGINFO, false);
 
       p = gbe_program_new_from_llvm(deviceID, NULL, out_module, llvm_ctx,
                                     dumpASMFileName.empty() ? NULL : dumpASMFileName.c_str(),
-                                    stringSize, err, errSize, optLevel, options);
+                                    stringSize, err, errSize, optLevel, options, source);
       if (err != NULL)
         *errSize += clangErrSize;
       if (OCL_OUTPUT_BUILD_LOG && options)
diff --git a/backend/src/backend/program.h b/backend/src/backend/program.h
index 45805f9..8a6ee9f 100644
--- a/backend/src/backend/program.h
+++ b/backend/src/backend/program.h
@@ -241,7 +241,8 @@ typedef gbe_program (gbe_program_new_from_llvm_cb)(uint32_t deviceID,
                                                    char *err,
                                                    size_t *err_size,
                                                    int optLevel,
-                                                   const char* options);
+                                                   const char* options,
+                                                   const char *source);
 extern gbe_program_new_from_llvm_cb *gbe_program_new_from_llvm;
 
 /*! link the programs from llvm level. */
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index 8cbb012..3e23395 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -294,7 +294,7 @@ namespace gbe {
     /*! Build a program from a ir::Unit */
     bool buildFromUnit(const ir::Unit &unit, std::string &error);
     /*! Buils a program from a LLVM source code */
-    bool buildFromLLVMFile(const char *fileName, const void* module, std::string &error, int optLevel);
+    bool buildFromLLVMFile(const char *fileName, const void* module, std::string &error, int optLevel, const char* source);
     /*! Buils a program from a OCL string */
     bool buildFromSource(const char *source, std::string &error);
     /*! Get size of the global constant arrays */
diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp
index 18e6827..33c1d63 100644
--- a/backend/src/llvm/llvm_gen_backend.hpp
+++ b/backend/src/llvm/llvm_gen_backend.hpp
@@ -146,7 +146,7 @@ namespace gbe
   llvm::FunctionPass* createPrintfParserPass(ir::Unit &unit);
 
   /*! Insert the time stamp for profiling. */
-  llvm::FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit &unit);
+  llvm::FunctionPass* createProfilingInserterPass(ir::Unit &unit, const char* source);
 
 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
   /* customized loop unrolling pass. */
diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp
index 53aa468..7c672e8 100644
--- a/backend/src/llvm/llvm_profiling.cpp
+++ b/backend/src/llvm/llvm_profiling.cpp
@@ -24,6 +24,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "llvm/Config/llvm-config.h"
 #if LLVM_VERSION_MINOR <= 2
@@ -83,10 +84,13 @@ namespace gbe
     IRBuilder<>* builder;
     Type* intTy;
     Type *ptrTy;
-    int profilingType;
+    uint32_t profilingType;
+    std::vector<std::pair<uint32_t, bool>> profLines;
+    std::string profKernel;
+    ir::Unit &unit;
+    const char* source;
 
-    ProfilingInserter(int profiling) : FunctionPass(ID), profilingType(profiling)
-    {
+    ProfilingInserter(ir::Unit &u, const char* s) : FunctionPass(ID), unit(u), source(s) {
       module = NULL;
       builder = NULL;
       intTy = NULL;
@@ -204,9 +208,9 @@ namespace gbe
     return changed;
   }
 
-  FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit &unit)
+  FunctionPass* createProfilingInserterPass(ir::Unit &unit, const char* source)
   {
-    return new ProfilingInserter(profilingType);
+    return new ProfilingInserter(unit, source);
   }
   char ProfilingInserter::ID = 0;
 
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
index b8ab1dd..75b2361 100644
--- a/backend/src/llvm/llvm_to_gen.cpp
+++ b/backend/src/llvm/llvm_to_gen.cpp
@@ -207,7 +207,7 @@ namespace gbe
   BVAR(OCL_OUTPUT_LLVM_AFTER_GEN, false);
 
   bool llvmToGen(ir::Unit &unit, const char *fileName,const void* module,
-                 int optLevel, bool strictMath, int profiling)
+                 int optLevel, bool strictMath, int profiling, const char* source)
   {
     std::string errInfo;
     std::unique_ptr<llvm::raw_fd_ostream> o = NULL;
@@ -288,7 +288,7 @@ namespace gbe
     passes.add(createCFGSimplificationPass());     // Merge & remove BBs
     passes.add(createLowerSwitchPass());           // simplify cfg will generate switch-case instruction
     if (profiling) {
-      passes.add(createProfilingInserterPass(profiling, unit));     // insert the time stamp for profiling.
+      passes.add(createProfilingInserterPass(unit, source));     // insert the time stamp for profiling.
     }
     passes.add(createScalarizePass());             // Expand all vector ops
 
diff --git a/backend/src/llvm/llvm_to_gen.hpp b/backend/src/llvm/llvm_to_gen.hpp
index 5667197..d5ebc6b 100644
--- a/backend/src/llvm/llvm_to_gen.hpp
+++ b/backend/src/llvm/llvm_to_gen.hpp
@@ -33,7 +33,7 @@ namespace gbe {
   /*! Convert the LLVM IR code to a GEN IR code,
 		  optLevel 0 equal to clang -O1 and 1 equal to clang -O2*/
   bool llvmToGen(ir::Unit &unit, const char *fileName, const void* module,
-                 int optLevel, bool strictMath, int profiling);
+                 int optLevel, bool strictMath, int profiling, const char* source);
 
 } /* namespace gbe */
 
diff --git a/src/cl_program.c b/src/cl_program.c
index fb8eea5..78a3ba9 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -408,7 +408,8 @@ cl_program_create_from_llvm(cl_context ctx,
       goto error;
   }
 
-  program->opaque = compiler_program_new_from_llvm(ctx->device->device_id, file_name, NULL, NULL, NULL, program->build_log_max_sz, program->build_log, &program->build_log_sz, 1, NULL);
+  program->opaque = compiler_program_new_from_llvm(ctx->device->device_id, file_name, NULL, NULL, NULL, program->build_log_max_sz,
+                              program->build_log, &program->build_log_sz, 1, NULL, NULL);
   if (UNLIKELY(program->opaque == NULL)) {
     err = CL_INVALID_PROGRAM;
     goto error;
-- 
1.9.1





More information about the Beignet mailing list