[Beignet] [PATCH v3 08/10] gbe: add vec_type_hint's type into functionAttributes.

xionghu.luo at intel.com xionghu.luo at intel.com
Wed Dec 2 21:26:39 PST 2015


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

for SPIR kernel, user may call clGetKernelInfo with CL_KERNEL_ATTRIBUTES
to query the functionAttributes.

v2: remove debug code.
v3: fix llvm 3.5 build fail.

Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
 backend/src/ir/type.cpp               |  6 +--
 backend/src/llvm/llvm_gen_backend.cpp | 72 +++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/backend/src/ir/type.cpp b/backend/src/ir/type.cpp
index 450ba61..682757b 100644
--- a/backend/src/ir/type.cpp
+++ b/backend/src/ir/type.cpp
@@ -32,11 +32,11 @@ namespace ir {
       case TYPE_S8: return out << "int8";
       case TYPE_U8: return out << "uint8";
       case TYPE_S16: return out << "int16";
-      case TYPE_U16: return out << "uin16";
+      case TYPE_U16: return out << "uint16";
       case TYPE_S32: return out << "int32";
-      case TYPE_U32: return out << "uin32";
+      case TYPE_U32: return out << "uint32";
       case TYPE_S64: return out << "int64";
-      case TYPE_U64: return out << "uin64";
+      case TYPE_U64: return out << "uint64";
       case TYPE_HALF: return out << "half";
       case TYPE_FLOAT: return out << "float";
       case TYPE_DOUBLE: return out << "double";
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index f011e1f..8d18c4a 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -114,6 +114,46 @@ namespace gbe
            type->isPointerTy();
   }
 
+  static std::string getTypeName(ir::Context &ctx, const Type *type, int sign)
+  {
+    GBE_ASSERT(isScalarType(type));
+    if (type->isFloatTy() == true)
+      return "float";
+    if (type->isHalfTy() == true)
+      return "half";
+    if (type->isDoubleTy() == true)
+      return "double";
+
+    GBE_ASSERT(type->isIntegerTy() == true);
+    if(sign) {
+      if (type == Type::getInt1Ty(type->getContext()))
+        return "char";
+      if (type == Type::getInt8Ty(type->getContext()))
+        return "char";
+      if (type == Type::getInt16Ty(type->getContext()))
+        return "short";
+      if (type == Type::getInt32Ty(type->getContext()))
+        return "int";
+      if (type == Type::getInt64Ty(type->getContext()))
+        return "long";
+    }
+    else
+    {
+      if (type == Type::getInt1Ty(type->getContext()))
+        return "uchar";
+      if (type == Type::getInt8Ty(type->getContext()))
+        return "uchar";
+      if (type == Type::getInt16Ty(type->getContext()))
+        return "ushort";
+      if (type == Type::getInt32Ty(type->getContext()))
+        return "uint";
+      if (type == Type::getInt64Ty(type->getContext()))
+        return "ulong";
+    }
+    GBE_ASSERTM(false, "Unsupported type.");
+    return "";
+  }
+
   /*! LLVM IR Type to Gen IR type translation */
   static ir::Type getType(ir::Context &ctx, const Type *type)
   {
@@ -1963,6 +2003,38 @@ namespace gbe
       } else if (attrName->getString() == "vec_type_hint") {
         GBE_ASSERT(attrNode->getNumOperands() == 3);
         functionAttributes += attrName->getString();
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
+        Value* V = attrNode->getOperand(1);
+#else
+        auto *Op1 = cast<ValueAsMetadata>(attrNode->getOperand(1));
+        Value *V = Op1 ? Op1->getValue() : NULL;
+#endif
+#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
+        ConstantInt *sign = dyn_cast<ConstantInt>(attrNode->getOperand(2));
+#else
+        ConstantInt *sign = mdconst::extract<ConstantInt>(attrNode->getOperand(2));
+#endif
+        size_t signValue = sign->getZExtValue();
+        Type* vtype = V->getType();
+        Type* stype = vtype;
+        uint32_t elemNum = 0;
+        if(vtype->isVectorTy()) {
+          VectorType *vectorType = cast<VectorType>(vtype);
+          stype = vectorType->getElementType();
+          elemNum = vectorType->getNumElements();
+        }
+
+        std::string typeName = getTypeName(ctx, stype, signValue);
+
+        std::stringstream param;
+        char buffer[100];
+        param <<"(";
+        param << typeName;
+        if(vtype->isVectorTy())
+          param << elemNum;
+        param <<")";
+        param >> buffer;
+        functionAttributes += buffer;
         functionAttributes += " ";
       } else if (attrName->getString() == "work_group_size_hint") {
         GBE_ASSERT(attrNode->getNumOperands() == 4);
-- 
1.9.1



More information about the Beignet mailing list