[Beignet] [Patch v2 02/10] gbe: use kernel_arg_base_type to recognize image arguments.

xionghu.luo at intel.com xionghu.luo at intel.com
Wed Nov 25 21:59:57 PST 2015


From: Luo Xionghu <xionghu.luo at intel.com>

we use string compare function to recognize the image type, but
image types could be defined to other type, so use kernel_arg_base_type
to recognize image arguments.
---
 backend/src/ir/function.hpp           | 15 ++++++++-------
 backend/src/llvm/llvm_gen_backend.cpp | 13 +++++++++++++
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp
index 265fdc3..b7853c1 100644
--- a/backend/src/ir/function.hpp
+++ b/backend/src/ir/function.hpp
@@ -177,27 +177,28 @@ namespace ir {
     struct InfoFromLLVM { // All the info about passed by llvm, using -cl-kernel-arg-info
       uint32_t addrSpace;
       std::string typeName;
+      std::string typeBaseName;
       std::string accessQual;
       std::string typeQual;
       std::string argName; // My different from arg->getName()
 
       bool isImage1dT() const {
-        return typeName.compare("image1d_t") == 0;
+        return typeBaseName.compare("image1d_t") == 0;
       }
       bool isImage1dArrayT() const {
-        return typeName.compare("image1d_array_t") == 0;
+        return typeBaseName.compare("image1d_array_t") == 0;
       }
       bool isImage1dBufferT() const {
-        return typeName.compare("image1d_buffer_t") == 0;
+        return typeBaseName.compare("image1d_buffer_t") == 0;
       }
       bool isImage2dT() const {
-        return typeName.compare("image2d_t") == 0;
+        return typeBaseName.compare("image2d_t") == 0;
       }
       bool isImage2dArrayT() const {
-        return typeName.compare("image2d_array_t") == 0;
+        return typeBaseName.compare("image2d_array_t") == 0;
       }
       bool isImage3dT() const {
-        return typeName.compare("image3d_t") == 0;
+        return typeBaseName.compare("image3d_t") == 0;
       }
 
       bool isImageType() const {
@@ -206,7 +207,7 @@ namespace ir {
       }
 
       bool isSamplerType() const {
-        return typeName.compare("sampler_t") == 0;
+        return typeBaseName.compare("sampler_t") == 0;
       }
 
     };
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index 36c5913..d1f48ab 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -1160,6 +1160,7 @@ namespace gbe
       BtiMap.insert(std::make_pair(&v, getNewBti(&v, false)));
     }
     MDNode *typeNameNode = NULL;
+    MDNode *typeBaseNameNode = NULL;
     MDNode *node = getKernelFunctionMetadata(&F);
     for(uint j = 0; j < node->getNumOperands() - 1; j++) {
       MDNode *attrNode = dyn_cast_or_null<MDNode>(node->getOperand(1 + j));
@@ -1169,12 +1170,18 @@ namespace gbe
       if (attrName->getString() == "kernel_arg_type") {
         typeNameNode = attrNode;
       }
+      if (attrName->getString() == "kernel_arg_base_type") {
+        typeBaseNameNode = attrNode;
+      }
     }
 
     unsigned argID = 0;
     ir::FunctionArgument::InfoFromLLVM llvmInfo;
     for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I, argID++) {
       llvmInfo.typeName= (cast<MDString>(typeNameNode->getOperand(1 + argID)))->getString();
+      if(typeBaseNameNode) {
+        llvmInfo.typeBaseName= (cast<MDString>(typeBaseNameNode->getOperand(1 + argID)))->getString();
+      }
       bool isImage = llvmInfo.isImageType();
       if (I->getType()->isPointerTy() || isImage) {
         BtiMap.insert(std::make_pair(I, getNewBti(I, isImage)));
@@ -1872,6 +1879,7 @@ namespace gbe
     ir::FunctionArgument::InfoFromLLVM llvmInfo;
     MDNode *addrSpaceNode = NULL;
     MDNode *typeNameNode = NULL;
+    MDNode *typeBaseNameNode = NULL;
     MDNode *accessQualNode = NULL;
     MDNode *typeQualNode = NULL;
     MDNode *argNameNode = NULL;
@@ -1927,6 +1935,8 @@ namespace gbe
         accessQualNode = attrNode;
       } else if (attrName->getString() == "kernel_arg_type") {
         typeNameNode = attrNode;
+      } else if (attrName->getString() == "kernel_arg_base_type") {
+        typeBaseNameNode = attrNode;
       } else if (attrName->getString() == "kernel_arg_type_qual") {
         typeQualNode = attrNode;
       } else if (attrName->getString() == "kernel_arg_name") {
@@ -1988,6 +1998,9 @@ namespace gbe
         llvmInfo.addrSpace = (mdconst::extract<ConstantInt>(addrSpaceNode->getOperand(1 + argID)))->getZExtValue();
 #endif
         llvmInfo.typeName = (cast<MDString>(typeNameNode->getOperand(1 + argID)))->getString();
+        if(typeBaseNameNode){
+          llvmInfo.typeBaseName = (cast<MDString>(typeBaseNameNode->getOperand(1 + argID)))->getString();
+        }
         llvmInfo.accessQual = (cast<MDString>(accessQualNode->getOperand(1 + argID)))->getString();
         llvmInfo.typeQual = (cast<MDString>(typeQualNode->getOperand(1 + argID)))->getString();
         if(argNameNode){
-- 
1.9.1



More information about the Beignet mailing list