From: Luo Xionghu <xionghu....@intel.com> for SPIR kernel, user may call clGetKernelInfo with CL_KERNEL_ATTRIBUTES to query the functionAttributes.
Signed-off-by: Luo Xionghu <xionghu....@intel.com> --- backend/src/ir/type.cpp | 6 ++-- backend/src/llvm/llvm_gen_backend.cpp | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 68 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 d4e18a5..027ae2b 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -111,6 +111,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) { @@ -1931,7 +1971,32 @@ namespace gbe } else if (attrName->getString() == "vec_type_hint") { GBE_ASSERT(attrNode->getNumOperands() == 3); functionAttributes += attrName->getString(); + auto *Op1 = cast<ValueAsMetadata>(attrNode->getOperand(1)); + ConstantInt *sign = mdconst::extract<ConstantInt>(attrNode->getOperand(2)); + size_t signValue = sign->getZExtValue(); + Value *V = Op1->getValue(); + 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 += " "; + std::cout << functionAttributes << std::endl; } else if (attrName->getString() == "work_group_size_hint") { GBE_ASSERT(attrNode->getNumOperands() == 4); #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5 -- 1.9.1 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet