Commit 3784f288 authored by Rishipal Singh Bhatia's avatar Rishipal Singh Bhatia

Moving more metadata variables to the new framework

Change-Id: I94c384387f617ac502bcd2b5eef3f0d217f23504
parent d447bc8d
......@@ -92,7 +92,7 @@ bool AddImplicitArgs::runOnModule(Module &M)
(ctx->getModuleMetaData()->compOpt.HasBufferOffsetArg ||
IGC_IS_FLAG_ENABLED(EnableSupportBufferOffset)))
{
ImplicitArgs::addBufferOffsetArgs(*pFunc, m_pMdUtils);
ImplicitArgs::addBufferOffsetArgs(*pFunc, m_pMdUtils, ctx->getModuleMetaData());
}
// Create the new function body and insert it into the module
......
......@@ -384,11 +384,15 @@ void ImplicitArgs::addNumberedArgs(llvm::Function& F, ImplicitArg::ArgMap& argMa
// Add one implicit argument for each pointer argument to global or constant buffer.
// Note that F is the original input function (ie, without implicit arguments).
void ImplicitArgs::addBufferOffsetArgs(llvm::Function& F, IGCMD::MetaDataUtils* pMdUtils)
void ImplicitArgs::addBufferOffsetArgs(llvm::Function& F, IGCMD::MetaDataUtils* pMdUtils, IGC::ModuleMetaData *modMD)
{
ImplicitArg::ArgMap OffsetArgs;
FunctionInfoMetaDataHandle funcInfoMD =
pMdUtils->getFunctionsInfoItem(const_cast<Function*>(&F));
assert(modMD->FuncMD.find(&F) != modMD->FuncMD.end());
FunctionMetaData* funcMD = &modMD->FuncMD.find(&F)->second;
for (auto& Arg : F.args() )
{
Value* AV = &Arg;
......@@ -401,11 +405,16 @@ void ImplicitArgs::addBufferOffsetArgs(llvm::Function& F, IGCMD::MetaDataUtils*
}
int argNo = Arg.getArgNo();
std::string argbaseType = "";
if (funcMD->m_OpenCLArgBaseTypes.size() > (unsigned)argNo)
argbaseType = funcMD->m_OpenCLArgBaseTypes[argNo];
// Do not generate implicit arg for any image arguments
KernelArg::ArgType ImgArgType;
if (KernelArg::isImage(
&Arg, funcInfoMD->getOpenCLArgBaseTypesItem(argNo), ImgArgType) ||
KernelArg::isSampler(&Arg, funcInfoMD->getOpenCLArgBaseTypesItem(argNo)))
&Arg, argbaseType, ImgArgType) ||
KernelArg::isSampler(&Arg, argbaseType))
{
continue;
}
......
......@@ -276,7 +276,7 @@ namespace IGC
/// implicit argument for each explicit pointer argument to global or constant buffer.
/// @param F The function for which to create the implicit argument's metadata
/// @param pMdUtils The Metadata API object
static void addBufferOffsetArgs(llvm::Function& F, IGCMD::MetaDataUtils* pMdUtils);
static void addBufferOffsetArgs(llvm::Function& F, IGCMD::MetaDataUtils* pMdUtils, IGC::ModuleMetaData* modMD);
/// @brief Returns the (implicit) function argument associated with the given implicit argument type
/// @param F The function for which the implict argument should be returned
......
......@@ -449,16 +449,20 @@ bool ProcessBuiltinMetaData::runOnModule(Module& M)
void ProcessBuiltinMetaData::updateBuiltinFunctionMetaData(llvm::Function* pFunc)
{
IGCMD::FunctionInfoMetaDataHandle fHandle = IGCMD::FunctionInfoMetaDataHandle(IGCMD::FunctionInfoMetaData::get());
IGC::ModuleMetaData* modMD = getAnalysis<CodeGenContextWrapper>().getCodeGenContext()->getModuleMetaData();
FunctionMetaData *funcMD = &modMD->FuncMD[pFunc]; //okay to insert if not present
fHandle->setType(IGC::IGCMD::FunctionTypeEnum::OtherFunctionType);
funcMD->functionType = IGC::FunctionTypeMD::UserFunction;
for (auto arg = pFunc->arg_begin(); arg != pFunc->arg_end(); ++arg)
{
std::string typeStr;
llvm::raw_string_ostream x(typeStr);
arg->getType()->print(x);
fHandle->addOpenCLArgNamesItem(arg->getName());
fHandle->addOpenCLArgAccessQualifiersItem("none");
fHandle->addOpenCLArgBaseTypesItem(x.str());
funcMD->m_OpenCLArgNames.push_back(arg->getName());
funcMD->m_OpenCLArgAccessQualifiers.push_back("none");
funcMD->m_OpenCLArgBaseTypes.push_back(x.str());
}
m_pMdUtil->setFunctionsInfoItem(pFunc, fHandle);
}
......@@ -331,17 +331,23 @@ void COpenCLKernel::CreateKernelArgInfo()
{
FunctionInfoMetaDataHandle funcInfoMD = m_pMdUtils->getFunctionsInfoItem(entry);
uint count = funcInfoMD->size_OpenCLArgAccessQualifiers();
uint count = 0;
if (m_Context->getModuleMetaData()->FuncMD.find(entry) != m_Context->getModuleMetaData()->FuncMD.end())
{
FunctionMetaData* funcMD = &m_Context->getModuleMetaData()->FuncMD[entry];
count = funcMD->m_OpenCLArgAccessQualifiers.size();
}
for (uint i = 0; i < count; ++i)
{
iOpenCL::KernelArgumentInfoAnnotation* kernelArgInfo = new iOpenCL::KernelArgumentInfoAnnotation();
FunctionMetaData* funcMD = &m_Context->getModuleMetaData()->FuncMD[entry];
// Format the strings the way the OpenCL runtime expects them
// The access qualifier is expected to have a "__" prefix,
// or an upper-case "NONE" if there is no qualifier
kernelArgInfo->AccessQualifier = funcInfoMD->getOpenCLArgAccessQualifiersItem(i);
kernelArgInfo->AccessQualifier = funcMD->m_OpenCLArgAccessQualifiers[i];
if (kernelArgInfo->AccessQualifier == "none" || kernelArgInfo->AccessQualifier == "")
{
kernelArgInfo->AccessQualifier = "NONE";
......@@ -352,7 +358,7 @@ void COpenCLKernel::CreateKernelArgInfo()
}
// The address space is expected to have a __ prefix
switch (funcInfoMD->getOpenCLArgAddressSpacesItem(i))
switch(funcMD->m_OpenCLArgAddressSpaces[i])
{
case ADDRESS_SPACE_CONSTANT:
kernelArgInfo->AddressQualifier = "__constant";
......@@ -373,13 +379,13 @@ void COpenCLKernel::CreateKernelArgInfo()
// ArgNames is not guaranteed to be present if -cl-kernel-arg-info
// is not passed in.
if (funcInfoMD->isOpenCLArgNamesHasValue())
if(funcMD->m_OpenCLArgNames.size() > i)
{
kernelArgInfo->ArgumentName = funcInfoMD->getOpenCLArgNamesItem(i);
kernelArgInfo->ArgumentName = funcMD->m_OpenCLArgNames[i];
}
// The type name is expected to also have the type size, appended after a ";"
kernelArgInfo->TypeName = funcInfoMD->getOpenCLArgTypesItem(i) + ";";
kernelArgInfo->TypeName = funcMD->m_OpenCLArgTypes[i] + ";";
// Unfortunately, unlike SPIR, legacy OCL uses an ABI that has byval pointers.
// So, if the parameter is a byval pointer, look at the contained type
......@@ -397,7 +403,7 @@ void COpenCLKernel::CreateKernelArgInfo()
}
// If there are no type qualifiers, "NONE" is expected
kernelArgInfo->TypeQualifier = funcInfoMD->getOpenCLArgTypeQualifiersItem(i);
kernelArgInfo->TypeQualifier = funcMD->m_OpenCLArgTypeQualifiers[i];
if (kernelArgInfo->TypeQualifier == "")
{
kernelArgInfo->TypeQualifier = "NONE";
......
......@@ -464,7 +464,7 @@ VISAVariableLocation VISAModule::GetVariableLocation(const llvm::Instruction* pI
unsigned int explicitArgsNum = IGCLLVM::GetFuncArgSize(m_pEntryFunc) - itr->second->size_ImplicitArgInfoList();
if (pArgument->getArgNo() < explicitArgsNum)
{
const std::string typeStr = itr->second->getOpenCLArgBaseTypesItem(pArgument->getArgNo());
const std::string typeStr = modMD->FuncMD[const_cast<Function*>(m_pEntryFunc)].m_OpenCLArgBaseTypes[pArgument->getArgNo()];
KernelArg::ArgType argType = KernelArg::calcArgType(pArgument, typeStr);
FunctionMetaData *funcMD = &modMD->FuncMD[const_cast<Function*>(m_pEntryFunc)];
ResourceAllocMD *resourceAlloc = &funcMD->resourceAlloc;
......
......@@ -1901,12 +1901,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const llvm::MDNode* pNode, bool hasId
m_LocalOffsets(getLocalOffsetsNode(pNode), true),
m_ResourceAlloc(ResourceAllocMetaData::get(getResourceAllocNode(pNode), true)),
m_OpenCLVectorTypeHint(VectorTypeHintMetaData::get(getOpenCLVectorTypeHintNode(pNode), true)),
m_OpenCLArgAddressSpaces(getOpenCLArgAddressSpacesNode(pNode), true),
m_OpenCLArgAccessQualifiers(getOpenCLArgAccessQualifiersNode(pNode), true),
m_OpenCLArgTypes(getOpenCLArgTypesNode(pNode), true),
m_OpenCLArgBaseTypes(getOpenCLArgBaseTypesNode(pNode), true),
m_OpenCLArgTypeQualifiers(getOpenCLArgTypeQualifiersNode(pNode), true),
m_OpenCLArgNames(getOpenCLArgNamesNode(pNode), true),
m_pNode(pNode)
{}
......@@ -1922,12 +1916,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(): m_Type("function_type"),
m_LocalOffsets("local_offsets"),
m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")),
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")),
m_OpenCLArgAddressSpaces("opencl_kernel_arg_addr_space"),
m_OpenCLArgAccessQualifiers("opencl_kernel_arg_access_qual"),
m_OpenCLArgTypes("opencl_kernel_arg_type"),
m_OpenCLArgBaseTypes("opencl_kernel_arg_base_type"),
m_OpenCLArgTypeQualifiers("opencl_kernel_arg_type_qual"),
m_OpenCLArgNames("opencl_kernel_arg_name"),
m_pNode(NULL)
{}
......@@ -1944,12 +1932,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const char* name):
m_LocalOffsets("local_offsets"),
m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")),
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")),
m_OpenCLArgAddressSpaces("opencl_kernel_arg_addr_space"),
m_OpenCLArgAccessQualifiers("opencl_kernel_arg_access_qual"),
m_OpenCLArgTypes("opencl_kernel_arg_type"),
m_OpenCLArgBaseTypes("opencl_kernel_arg_base_type"),
m_OpenCLArgTypeQualifiers("opencl_kernel_arg_type_qual"),
m_OpenCLArgNames("opencl_kernel_arg_name"),
m_pNode(NULL)
{}
......@@ -2006,40 +1988,6 @@ bool FunctionInfoMetaData::hasValue() const
return true;
}
if (m_OpenCLArgAddressSpaces.hasValue())
{
return true;
}
if (m_OpenCLArgAccessQualifiers.hasValue())
{
return true;
}
if (m_OpenCLArgTypes.hasValue())
{
return true;
}
if (m_OpenCLArgBaseTypes.hasValue())
{
return true;
}
if (m_OpenCLArgTypeQualifiers.hasValue())
{
return true;
}
if (m_OpenCLArgNames.hasValue())
{
return true;
}
return NULL != m_pNode || dirty();
}
......@@ -2083,30 +2031,6 @@ bool FunctionInfoMetaData::dirty() const
{
return true;
}
if( m_OpenCLArgAddressSpaces.dirty() )
{
return true;
}
if( m_OpenCLArgAccessQualifiers.dirty() )
{
return true;
}
if( m_OpenCLArgTypes.dirty() )
{
return true;
}
if( m_OpenCLArgBaseTypes.dirty() )
{
return true;
}
if( m_OpenCLArgTypeQualifiers.dirty() )
{
return true;
}
if( m_OpenCLArgNames.dirty() )
{
return true;
}
return false;
}
......@@ -2123,12 +2047,6 @@ void FunctionInfoMetaData::discardChanges()
m_LocalOffsets.discardChanges();
m_ResourceAlloc.discardChanges();
m_OpenCLVectorTypeHint.discardChanges();
m_OpenCLArgAddressSpaces.discardChanges();
m_OpenCLArgAccessQualifiers.discardChanges();
m_OpenCLArgTypes.discardChanges();
m_OpenCLArgBaseTypes.discardChanges();
m_OpenCLArgTypeQualifiers.discardChanges();
m_OpenCLArgNames.discardChanges();
}
///
......@@ -2183,37 +2101,6 @@ llvm::Metadata* FunctionInfoMetaData::generateNode(llvm::LLVMContext& context) c
{
args.push_back(m_OpenCLVectorTypeHint.generateNode(context));
}
if (isOpenCLArgAddressSpacesHasValue())
{
args.push_back(m_OpenCLArgAddressSpaces.generateNode(context));
}
if (isOpenCLArgAccessQualifiersHasValue())
{
args.push_back( m_OpenCLArgAccessQualifiers.generateNode(context));
}
if (isOpenCLArgTypesHasValue())
{
args.push_back( m_OpenCLArgTypes.generateNode(context));
}
if (isOpenCLArgBaseTypesHasValue())
{
args.push_back( m_OpenCLArgBaseTypes.generateNode(context));
}
if (isOpenCLArgTypeQualifiersHasValue())
{
args.push_back( m_OpenCLArgTypeQualifiers.generateNode(context));
}
if (isOpenCLArgNamesHasValue())
{
args.push_back( m_OpenCLArgNames.generateNode(context));
}
return llvm::MDNode::get(context, args);
}
......@@ -2246,12 +2133,6 @@ void FunctionInfoMetaData::save(llvm::LLVMContext& context, llvm::MDNode* pNode)
m_LocalOffsets.save(context, llvm::cast<llvm::MDNode>(getLocalOffsetsNode(pNode)));
m_ResourceAlloc.save(context, llvm::cast<llvm::MDNode>(getResourceAllocNode(pNode)));
m_OpenCLVectorTypeHint.save(context, llvm::cast<llvm::MDNode>(getOpenCLVectorTypeHintNode(pNode)));
m_OpenCLArgAddressSpaces.save(context, llvm::cast<llvm::MDNode>(getOpenCLArgAddressSpacesNode(pNode)));
m_OpenCLArgAccessQualifiers.save(context, llvm::cast<llvm::MDNode>(getOpenCLArgAccessQualifiersNode(pNode)));
m_OpenCLArgTypes.save(context, llvm::cast<llvm::MDNode>(getOpenCLArgTypesNode(pNode)));
m_OpenCLArgBaseTypes.save(context, llvm::cast<llvm::MDNode>(getOpenCLArgBaseTypesNode(pNode)));
m_OpenCLArgTypeQualifiers.save(context, llvm::cast<llvm::MDNode>(getOpenCLArgTypeQualifiersNode(pNode)));
m_OpenCLArgNames.save(context, llvm::cast<llvm::MDNode>(getOpenCLArgNamesNode(pNode)));
}
llvm::Metadata* FunctionInfoMetaData::getTypeNode( const llvm::MDNode* pParentNode) const
......@@ -2434,114 +2315,6 @@ llvm::MDNode* FunctionInfoMetaData::getOpenCLVectorTypeHintNode( const llvm::MDN
return NULL;
}
llvm::MDNode* FunctionInfoMetaData::getOpenCLArgAddressSpacesNode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
{
return NULL;
}
unsigned int offset = _Mybase::getStartIndex();
for(NodeIterator i = NodeIterator(pParentNode, 0+offset), e = NodeIterator(pParentNode); i != e; ++i )
{
if( isNamedNode(i.get(), "opencl_kernel_arg_addr_space") )
{
return llvm::dyn_cast<llvm::MDNode>(i.get());
}
}
return NULL;
}
llvm::MDNode* FunctionInfoMetaData::getOpenCLArgAccessQualifiersNode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
{
return NULL;
}
unsigned int offset = _Mybase::getStartIndex();
for(NodeIterator i = NodeIterator(pParentNode, 0+offset), e = NodeIterator(pParentNode); i != e; ++i )
{
if( isNamedNode(i.get(), "opencl_kernel_arg_access_qual") )
{
return llvm::dyn_cast<llvm::MDNode>(i.get());
}
}
return NULL;
}
llvm::MDNode* FunctionInfoMetaData::getOpenCLArgTypesNode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
{
return NULL;
}
unsigned int offset = _Mybase::getStartIndex();
for(NodeIterator i = NodeIterator(pParentNode, 0+offset), e = NodeIterator(pParentNode); i != e; ++i )
{
if( isNamedNode(i.get(), "opencl_kernel_arg_type") )
{
return llvm::dyn_cast<llvm::MDNode>(i.get());
}
}
return NULL;
}
llvm::MDNode* FunctionInfoMetaData::getOpenCLArgBaseTypesNode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
{
return NULL;
}
unsigned int offset = _Mybase::getStartIndex();
for(NodeIterator i = NodeIterator(pParentNode, 0+offset), e = NodeIterator(pParentNode); i != e; ++i )
{
if( isNamedNode(i.get(), "opencl_kernel_arg_base_type") )
{
return llvm::dyn_cast<llvm::MDNode>(i.get());
}
}
return NULL;
}
llvm::MDNode* FunctionInfoMetaData::getOpenCLArgTypeQualifiersNode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
{
return NULL;
}
unsigned int offset = _Mybase::getStartIndex();
for(NodeIterator i = NodeIterator(pParentNode, 0+offset), e = NodeIterator(pParentNode); i != e; ++i )
{
if( isNamedNode(i.get(), "opencl_kernel_arg_type_qual") )
{
return llvm::dyn_cast<llvm::MDNode>(i.get());
}
}
return NULL;
}
llvm::MDNode* FunctionInfoMetaData::getOpenCLArgNamesNode(const llvm::MDNode* pParentNode) const
{
if (!pParentNode)
{
return NULL;
}
unsigned int offset = _Mybase::getStartIndex();
for (NodeIterator i = NodeIterator(pParentNode, 0 + offset), e = NodeIterator(pParentNode); i != e; ++i)
{
if (isNamedNode(i.get(), "opencl_kernel_arg_name"))
{
return llvm::dyn_cast<llvm::MDNode>(i.get());
}
}
return NULL;
}
static bool isNamedNode(const llvm::Metadata* pNode, const char* name)
{
const llvm::MDNode* pMDNode = llvm::dyn_cast<llvm::MDNode>(pNode);
......
This diff is collapsed.
......@@ -153,20 +153,22 @@ namespace //Anonymous
class MetadataBuilder
{
IGC::IGCMD::MetaDataUtils* _pMdUtils;
IGC::ModuleMetaData* modMD;
DataContext& _dataContext;
public:
MetadataBuilder(IGC::IGCMD::MetaDataUtils* pMdUtils, DataContext& dataContext)
: _pMdUtils(pMdUtils), _dataContext(dataContext) {}
MetadataBuilder(IGC::IGCMD::MetaDataUtils* pMdUtils, DataContext& dataContext, IGC::ModuleMetaData* moduleMD)
: modMD(moduleMD), _pMdUtils(pMdUtils), _dataContext(dataContext) {}
/// Return function metadata if function is kernel
IGC::IGCMD::FunctionInfoMetaDataHandle getKernelMetadata(const llvm::Function* func)
IGC::FunctionMetaData* getKernelMetadata(const llvm::Function* func)
{
if (isEntryFunc(_pMdUtils, func))
{
return _pMdUtils->getFunctionsInfoItem(const_cast<llvm::Function*>(func));
if (modMD->FuncMD.find(const_cast<llvm::Function*>(func)) != modMD->FuncMD.end())
return &modMD->FuncMD[const_cast<llvm::Function*>(func)];
}
return IGC::IGCMD::FunctionInfoMetaDataHandle(nullptr);
return nullptr;
}
bool eraseKernelMetadata(llvm::Function* func, IGC::ModuleMetaData* modMD) {
......@@ -185,21 +187,22 @@ namespace //Anonymous
}
/// Return kernel argument type name from metadata
IGC::IGCMD::FunctionInfoMetaData::OpenCLArgBaseTypesList::item_type getKernelArgTypeName(const llvm::Function* func, unsigned argNum)
std::string getKernelArgTypeName(const llvm::Function* func, unsigned argNum)
{
auto funcInfoMD = getOrEmitKernelMetadata(func);
assert((funcInfoMD.get() != nullptr) && "cannot get or emit for kernel metadata");
return funcInfoMD->getOpenCLArgBaseTypesItem(argNum);
auto funcInfoMD = getOrEmitKernelMetadata(const_cast<llvm::Function*>(func));
assert((funcInfoMD != nullptr) && "cannot get or emit for kernel metadata");
assert(funcInfoMD->m_OpenCLArgBaseTypes.size() > (unsigned) argNum);
return funcInfoMD->m_OpenCLArgBaseTypes[argNum];
}
/// Return function metadata if function is kernel, emit new kernel metadata if not.
IGC::IGCMD::FunctionInfoMetaDataHandle getOrEmitKernelMetadata(const llvm::Function* func)
FunctionMetaData* getOrEmitKernelMetadata(const llvm::Function* func)
{
auto kernelMD = getKernelMetadata(func);
if (kernelMD.get() == nullptr)
if (kernelMD == nullptr)
{
return EmitKernelMetadata(func);
EmitKernelMetadata(const_cast<llvm::Function*>(func));
kernelMD = getKernelMetadata(func);
}
return kernelMD;
}
......@@ -223,7 +226,7 @@ namespace //Anonymous
// Function responsible for emitting special meta data for block dispatcher functions //
// this will be part of stadard meta data layout and will be consumed by the Target //
/////////////////////////////////////////////////////////////////////////////////////////////////
IGC::IGCMD::FunctionInfoMetaDataHandle EmitKernelMetadata(const llvm::Function* kernelFunc);
void EmitKernelMetadata(const llvm::Function* kernelFunc);
};
/////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -1193,10 +1196,10 @@ namespace //Anonymous
public:
DataContext(IGC::IGCMD::MetaDataUtils* pMdUtils)
DataContext(IGC::ModuleMetaData* modMD, IGC::IGCMD::MetaDataUtils* pMdUtils)
: _blocksNum(0)
, _kindQuery(*this)
, _MDBuilder(pMdUtils, *this)
, _MDBuilder(pMdUtils, *this, modMD)
{}
const KindQuery& getKindQuery() { return _kindQuery; }
......@@ -1289,7 +1292,7 @@ namespace //Anonymous
auto modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();
// dataContext "owns" all created objects in internal "database"
DataContext dataContext(pMdUtils);
DataContext dataContext(modMD, pMdUtils);
// Inline functions which have device exec calls up to kernel or block_invoke level
// to properly resolve parent argument number for the following case:
......@@ -1608,7 +1611,7 @@ namespace //Anonymous
/////////////////////////////////////////////////////////////////////////////////////////////////
// MetadataBuilder implementation
/////////////////////////////////////////////////////////////////////////////////////////////////
IGC::IGCMD::FunctionInfoMetaDataHandle MetadataBuilder::EmitKernelMetadata(const llvm::Function* kernelFunc)
void MetadataBuilder::EmitKernelMetadata(const llvm::Function* kernelFunc)
{
// Helper structure for pretty printing types
struct TypeNameHelper {
......@@ -1670,11 +1673,13 @@ namespace //Anonymous
//link dispatchMd to dispatch kernel
IGC::IGCMD::FunctionInfoMetaDataHandle dispatchMd = _pMdUtils->getOrInsertFunctionsInfoItem(const_cast<llvm::Function*>(kernelFunc));
auto funcMD = &modMD->FuncMD[const_cast<llvm::Function*>(kernelFunc)];//insert if not present
//set function type for dispatch
dispatchMd->setType(IGC::IGCMD::FunctionTypeEnum::EntryFunctionType);
funcMD->functionType = IGC::FunctionTypeMD::KernelFunction;
for (auto& arg : kernelFunc->args())
{
auto argType = arg.getType();
......@@ -1699,16 +1704,16 @@ namespace //Anonymous
TypeNameHelper::Print(argType, os);
}
dispatchMd->addOpenCLArgAddressSpacesItem(addrSpace); // !"kernel_arg_addr_space"
dispatchMd->addOpenCLArgAccessQualifiersItem(accessQual); // !"kernel_arg_access_qual"
dispatchMd->addOpenCLArgTypesItem(typeName); // !"kernel_arg_type"
dispatchMd->addOpenCLArgTypeQualifiersItem(""); // !"kernel_arg_type_qual"
dispatchMd->addOpenCLArgBaseTypesItem(typeName); // !"kernel_arg_base_type"
dispatchMd->addOpenCLArgNamesItem(arg.getName()); // !"kernel_arg_name"
funcMD->m_OpenCLArgAddressSpaces.push_back(addrSpace);
funcMD->m_OpenCLArgAccessQualifiers.push_back(accessQual);
funcMD->m_OpenCLArgTypes.push_back(typeName);
funcMD->m_OpenCLArgTypeQualifiers.push_back("");
funcMD->m_OpenCLArgBaseTypes.push_back(typeName);
funcMD->m_OpenCLArgNames.push_back(arg.getName());
}
//save changes
_pMdUtils->save(kernelFunc->getContext());
return dispatchMd;
return;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -1770,7 +1775,7 @@ namespace //Anonymous
bool KindQuery::isKernel(const llvm::Function* func) const
{
return _dataContext.getMetaDataBuilder().getKernelMetadata(func).get() != nullptr;
return _dataContext.getMetaDataBuilder().getKernelMetadata(func) != nullptr;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -1046,11 +1046,22 @@ KernelArgs::KernelArgs(const Function& F, const DataLayout* DL, MetaDataUtils* p
}
}
std::string argBaseType = "";
std::string argAccessQualItem = "";
if (it != moduleMD->FuncMD.end())
{
if (it->second.m_OpenCLArgBaseTypes.size() > (unsigned)i)
argBaseType = it->second.m_OpenCLArgBaseTypes[i];
if (it->second.m_OpenCLArgAccessQualifiers.size() > (unsigned)i)
argAccessQualItem = it->second.m_OpenCLArgAccessQualifiers[i];
}
KernelArg kernelArg = KernelArg(
&(*funcArg),
DL,
funcInfoMD->getOpenCLArgBaseTypesItem(i),
funcInfoMD->getOpenCLArgAccessQualifiersItem(i),
argBaseType,
argAccessQualItem,
location_index,
location_count,
needAllocation,
......
......@@ -228,9 +228,10 @@ bool SPIRMetaDataTranslation::runOnModule(Module& M)
{
SPIRMD::KernelMetaData::ArgAddressSpacesList::const_iterator i = spirKernel->begin_ArgAddressSpaces();
SPIRMD::KernelMetaData::ArgAddressSpacesList::const_iterator e = spirKernel->end_ArgAddressSpaces();
for (; i != e; ++i)
{
fHandle->addOpenCLArgAddressSpacesItem(*i);
funcMD.m_OpenCLArgAddressSpaces.push_back(*i);
}
}
......@@ -241,7 +242,7 @@ bool SPIRMetaDataTranslation::runOnModule(Module& M)
SPIRMD::KernelMetaData::ArgAccessQualifiersList::const_iterator e = spirKernel->end_ArgAccessQualifiers();
for (; i != e; ++i)
{
fHandle->addOpenCLArgAccessQualifiersItem(*i);
funcMD.m_OpenCLArgAccessQualifiers.push_back(*i);
}
}
......@@ -252,7 +253,7 @@ bool SPIRMetaDataTranslation::runOnModule(Module& M)
SPIRMD::KernelMetaData::ArgTypesList::const_iterator e = spirKernel->end_ArgTypes();
for (; i != e; ++i)
{
fHandle->addOpenCLArgTypesItem(*i);
funcMD.m_OpenCLArgTypes.push_back(*i);
}
}
......@@ -263,7 +264,7 @@ bool SPIRMetaDataTranslation::runOnModule(Module& M)
SPIRMD::KernelMetaData::ArgBaseTypesList::const_iterator e = spirKernel->end_ArgBaseTypes();
for (; i != e; ++i)
{
fHandle->addOpenCLArgBaseTypesItem(*i);
funcMD.m_OpenCLArgBaseTypes.push_back(*i);
}
}
......@@ -274,7 +275,7 @@ bool SPIRMetaDataTranslation::runOnModule(Module& M)
SPIRMD::KernelMetaData::ArgTypeQualifiersList::const_iterator e = spirKernel->end_ArgTypeQualifiers();
for (; i != e; ++i)
{
fHandle->addOpenCLArgTypeQualifiersItem(*i);
funcMD.m_OpenCLArgTypeQualifiers.push_back(*i);
}
}
......@@ -285,7 +286,7 @@ bool SPIRMetaDataTranslation::runOnModule(Module& M)
SPIRMD::KernelMetaData::ArgNamesList::const_iterator e = spirKernel->end_ArgNames();
for (; i != e; ++i)
{
fHandle->addOpenCLArgNamesItem(*i);
funcMD.m_OpenCLArgNames.push_back(*i);
}
}
......
......@@ -75,6 +75,7 @@ namespace IGC
bool isEmulationArg = 0;
};
//to hold metadata of every function
struct FunctionMetaData
{
......@@ -93,6 +94,16 @@ namespace IGC
bool groupIDPresent = false;
int privateMemoryPerWI = 0;
bool globalIDPresent = false;
std::vector<int32_t> m_OpenCLArgAddressSpaces;
std::vector<std::string> m_OpenCLArgAccessQualifiers;
std::vector<std::string> m_OpenCLArgTypes;
std::vector<std::string> m_OpenCLArgBaseTypes;
std::vector<std::string> m_OpenCLArgTypeQualifiers;
std::vector<std::string> m_OpenCLArgNames;
};
// isCloned member is added to mark whether a function is clone
......