[06/15] Backend: Generate profiling instructions in gen_backend

Submitted by junyan.he@inbox.com on Aug. 12, 2015, 8:49 a.m.

Details

Message ID 1439369340-21581-1-git-send-email-junyan.he@inbox.com
State New
Headers show

Not browsing as part of any series.

Commit Message

junyan.he@inbox.com Aug. 12, 2015, 8:49 a.m.
From: Junyan He <junyan.he@linux.intel.com>

Signed-off-by: Junyan He <junyan.he@linux.intel.com>
---
 backend/src/llvm/llvm_gen_backend.cpp      |   45 ++++++++++++++++++++++++++++
 backend/src/llvm/llvm_gen_backend.hpp      |    3 ++
 backend/src/llvm/llvm_gen_ocl_function.hxx |    5 ++++
 3 files changed, 53 insertions(+)

Patch hide | download patch | download mbox

diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index 4905415..32ecd6c 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -1112,6 +1112,9 @@  namespace gbe
     } else if (origin->getName().equals(StringRef("__gen_ocl_printf_index_buf"))) {
       new_bti = btiBase;
       incBtiBase();
+    } else if (origin->getName().equals(StringRef("__gen_ocl_timestamp_buf"))) {
+      new_bti = btiBase;
+      incBtiBase();
     }
     else if (isa<GlobalVariable>(origin)
         && dyn_cast<GlobalVariable>(origin)->isConstant()) {
@@ -2485,6 +2488,9 @@  namespace gbe
         } else if(v.getName().equals(StringRef("__gen_ocl_printf_index_buf"))) {
           ctx.getFunction().getPrintfSet()->setIndexBufBTI(BtiMap.find(const_cast<GlobalVariable*>(&v))->second);
           regTranslator.newScalarProxy(ir::ocl::printfiptr, const_cast<GlobalVariable*>(&v));
+        } else if(v.getName().equals(StringRef("__gen_ocl_profiling_buf"))) {
+          ctx.getUnit().getProfilingInfo()->setBTI(BtiMap.find(const_cast<GlobalVariable*>(&v))->second);
+          regTranslator.newScalarProxy(ir::ocl::profilingbptr, const_cast<GlobalVariable*>(&v));
         } else if(v.getName().str().substr(0, 4) == ".str") {
           /* When there are multi printf statements in multi kernel fucntions within the same
              translate unit, if they have the same sting parameter, such as
@@ -3494,6 +3500,8 @@  namespace gbe
         this->newRegister(&I);
         break;
       case GEN_OCL_PRINTF:
+      case GEN_OCL_CALC_TIMESTAMP:
+      case GEN_OCL_STORE_PROFILING:
         break;
       case GEN_OCL_NOT_FOUND:
       default:
@@ -4179,6 +4187,43 @@  namespace gbe
             assert(fmt);
             break;
           }
+          case GEN_OCL_CALC_TIMESTAMP:
+          {
+            GBE_ASSERT(AI != AE);
+            ConstantInt *CI = dyn_cast<ConstantInt>(*AI);
+            GBE_ASSERT(CI);
+            uint32_t pointNum = CI->getZExtValue();
+            AI++;
+            GBE_ASSERT(AI != AE);
+            CI = dyn_cast<ConstantInt>(*AI);
+            GBE_ASSERT(CI);
+            uint32_t tsType = CI->getZExtValue();
+            ctx.CALC_TIMESTAMP(pointNum, tsType);
+            break;
+          }
+          case GEN_OCL_STORE_PROFILING:
+          {
+            GBE_ASSERT(AI != AE);
+            Value* llvmPtr = *AI;
+            Value *bti = getBtiRegister(llvmPtr);
+            Value *ptrBase = getPointerBase(llvmPtr);
+            ir::Register pointer = this->getRegister(llvmPtr);
+            ir::Register baseReg = this->getRegister(ptrBase);
+            GBE_ASSERT(isa<ConstantInt>(bti)); //Should never be mixed pointer.
+            uint32_t index = cast<ConstantInt>(bti)->getZExtValue();
+            GBE_ASSERT(btiToGen(index) == ir::MEM_GLOBAL);
+            const ir::Register ptr = ctx.reg(ctx.getPointerFamily());
+            ctx.SUB(ir::TYPE_U32, ptr, pointer, baseReg);
+
+            ++AI;
+            GBE_ASSERT(AI != AE);
+            ConstantInt *CI = dyn_cast<ConstantInt>(*AI);
+            GBE_ASSERT(CI);
+            uint32_t ptype = CI->getZExtValue();
+            ctx.getUnit().getProfilingInfo()->setProfilingType(ptype);
+            ctx.STORE_PROFILING(ptr, index, ptype);
+            break;
+          }
           case GEN_OCL_SIMD_SIZE:
           {
             const ir::Register dst = this->getRegister(&I);
diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp
index 1f16557..cb08a28 100644
--- a/backend/src/llvm/llvm_gen_backend.hpp
+++ b/backend/src/llvm/llvm_gen_backend.hpp
@@ -146,6 +146,9 @@  namespace gbe
   /*! Passer the printf function call. */
   llvm::FunctionPass* createPrintfParserPass();
 
+  /*! Insert the time stamp for profiling. */
+  llvm::FunctionPass* createProfilingInserterPass(int profilingType);
+
 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
   /* customized loop unrolling pass. */
   llvm::LoopPass *createCustomLoopUnrollPass();
diff --git a/backend/src/llvm/llvm_gen_ocl_function.hxx b/backend/src/llvm/llvm_gen_ocl_function.hxx
index cabb225..0a6e1da 100644
--- a/backend/src/llvm/llvm_gen_ocl_function.hxx
+++ b/backend/src/llvm/llvm_gen_ocl_function.hxx
@@ -170,3 +170,8 @@  DECL_LLVM_GEN_FUNCTION(REGION, __gen_ocl_region)
 
 // printf function
 DECL_LLVM_GEN_FUNCTION(PRINTF, __gen_ocl_printf)
+
+// store timestamp function
+DECL_LLVM_GEN_FUNCTION(CALC_TIMESTAMP, __gen_ocl_calc_timestamp)
+// store profiling info to the mem.
+DECL_LLVM_GEN_FUNCTION(STORE_PROFILING, __gen_ocl_store_profiling)