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) ...@@ -92,7 +92,7 @@ bool AddImplicitArgs::runOnModule(Module &M)
(ctx->getModuleMetaData()->compOpt.HasBufferOffsetArg || (ctx->getModuleMetaData()->compOpt.HasBufferOffsetArg ||
IGC_IS_FLAG_ENABLED(EnableSupportBufferOffset))) 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 // Create the new function body and insert it into the module
......
...@@ -384,11 +384,15 @@ void ImplicitArgs::addNumberedArgs(llvm::Function& F, ImplicitArg::ArgMap& argMa ...@@ -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. // 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). // 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; ImplicitArg::ArgMap OffsetArgs;
FunctionInfoMetaDataHandle funcInfoMD = FunctionInfoMetaDataHandle funcInfoMD =
pMdUtils->getFunctionsInfoItem(const_cast<Function*>(&F)); 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() ) for (auto& Arg : F.args() )
{ {
Value* AV = &Arg; Value* AV = &Arg;
...@@ -401,11 +405,16 @@ void ImplicitArgs::addBufferOffsetArgs(llvm::Function& F, IGCMD::MetaDataUtils* ...@@ -401,11 +405,16 @@ void ImplicitArgs::addBufferOffsetArgs(llvm::Function& F, IGCMD::MetaDataUtils*
} }
int argNo = Arg.getArgNo(); 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 // Do not generate implicit arg for any image arguments
KernelArg::ArgType ImgArgType; KernelArg::ArgType ImgArgType;
if (KernelArg::isImage( if (KernelArg::isImage(
&Arg, funcInfoMD->getOpenCLArgBaseTypesItem(argNo), ImgArgType) || &Arg, argbaseType, ImgArgType) ||
KernelArg::isSampler(&Arg, funcInfoMD->getOpenCLArgBaseTypesItem(argNo))) KernelArg::isSampler(&Arg, argbaseType))
{ {
continue; continue;
} }
......
...@@ -276,7 +276,7 @@ namespace IGC ...@@ -276,7 +276,7 @@ namespace IGC
/// implicit argument for each explicit pointer argument to global or constant buffer. /// 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 F The function for which to create the implicit argument's metadata
/// @param pMdUtils The Metadata API object /// @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 /// @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 /// @param F The function for which the implict argument should be returned
......
...@@ -449,16 +449,20 @@ bool ProcessBuiltinMetaData::runOnModule(Module& M) ...@@ -449,16 +449,20 @@ bool ProcessBuiltinMetaData::runOnModule(Module& M)
void ProcessBuiltinMetaData::updateBuiltinFunctionMetaData(llvm::Function* pFunc) void ProcessBuiltinMetaData::updateBuiltinFunctionMetaData(llvm::Function* pFunc)
{ {
IGCMD::FunctionInfoMetaDataHandle fHandle = IGCMD::FunctionInfoMetaDataHandle(IGCMD::FunctionInfoMetaData::get()); 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); fHandle->setType(IGC::IGCMD::FunctionTypeEnum::OtherFunctionType);
funcMD->functionType = IGC::FunctionTypeMD::UserFunction;
for (auto arg = pFunc->arg_begin(); arg != pFunc->arg_end(); ++arg) for (auto arg = pFunc->arg_begin(); arg != pFunc->arg_end(); ++arg)
{ {
std::string typeStr; std::string typeStr;
llvm::raw_string_ostream x(typeStr); llvm::raw_string_ostream x(typeStr);
arg->getType()->print(x); arg->getType()->print(x);
fHandle->addOpenCLArgNamesItem(arg->getName()); funcMD->m_OpenCLArgNames.push_back(arg->getName());
fHandle->addOpenCLArgAccessQualifiersItem("none"); funcMD->m_OpenCLArgAccessQualifiers.push_back("none");
fHandle->addOpenCLArgBaseTypesItem(x.str()); funcMD->m_OpenCLArgBaseTypes.push_back(x.str());
} }
m_pMdUtil->setFunctionsInfoItem(pFunc, fHandle); m_pMdUtil->setFunctionsInfoItem(pFunc, fHandle);
} }
...@@ -331,17 +331,23 @@ void COpenCLKernel::CreateKernelArgInfo() ...@@ -331,17 +331,23 @@ void COpenCLKernel::CreateKernelArgInfo()
{ {
FunctionInfoMetaDataHandle funcInfoMD = m_pMdUtils->getFunctionsInfoItem(entry); 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) for (uint i = 0; i < count; ++i)
{ {
iOpenCL::KernelArgumentInfoAnnotation* kernelArgInfo = new iOpenCL::KernelArgumentInfoAnnotation(); iOpenCL::KernelArgumentInfoAnnotation* kernelArgInfo = new iOpenCL::KernelArgumentInfoAnnotation();
FunctionMetaData* funcMD = &m_Context->getModuleMetaData()->FuncMD[entry];
// Format the strings the way the OpenCL runtime expects them // Format the strings the way the OpenCL runtime expects them
// The access qualifier is expected to have a "__" prefix, // The access qualifier is expected to have a "__" prefix,
// or an upper-case "NONE" if there is no qualifier // 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 == "") if (kernelArgInfo->AccessQualifier == "none" || kernelArgInfo->AccessQualifier == "")
{ {
kernelArgInfo->AccessQualifier = "NONE"; kernelArgInfo->AccessQualifier = "NONE";
...@@ -352,7 +358,7 @@ void COpenCLKernel::CreateKernelArgInfo() ...@@ -352,7 +358,7 @@ void COpenCLKernel::CreateKernelArgInfo()
} }
// The address space is expected to have a __ prefix // The address space is expected to have a __ prefix
switch (funcInfoMD->getOpenCLArgAddressSpacesItem(i)) switch(funcMD->m_OpenCLArgAddressSpaces[i])
{ {
case ADDRESS_SPACE_CONSTANT: case ADDRESS_SPACE_CONSTANT:
kernelArgInfo->AddressQualifier = "__constant"; kernelArgInfo->AddressQualifier = "__constant";
...@@ -373,13 +379,13 @@ void COpenCLKernel::CreateKernelArgInfo() ...@@ -373,13 +379,13 @@ void COpenCLKernel::CreateKernelArgInfo()
// ArgNames is not guaranteed to be present if -cl-kernel-arg-info // ArgNames is not guaranteed to be present if -cl-kernel-arg-info
// is not passed in. // 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 ";" // 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. // 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 // So, if the parameter is a byval pointer, look at the contained type
...@@ -397,7 +403,7 @@ void COpenCLKernel::CreateKernelArgInfo() ...@@ -397,7 +403,7 @@ void COpenCLKernel::CreateKernelArgInfo()
} }
// If there are no type qualifiers, "NONE" is expected // If there are no type qualifiers, "NONE" is expected
kernelArgInfo->TypeQualifier = funcInfoMD->getOpenCLArgTypeQualifiersItem(i); kernelArgInfo->TypeQualifier = funcMD->m_OpenCLArgTypeQualifiers[i];
if (kernelArgInfo->TypeQualifier == "") if (kernelArgInfo->TypeQualifier == "")
{ {
kernelArgInfo->TypeQualifier = "NONE"; kernelArgInfo->TypeQualifier = "NONE";
......
...@@ -464,7 +464,7 @@ VISAVariableLocation VISAModule::GetVariableLocation(const llvm::Instruction* pI ...@@ -464,7 +464,7 @@ VISAVariableLocation VISAModule::GetVariableLocation(const llvm::Instruction* pI
unsigned int explicitArgsNum = IGCLLVM::GetFuncArgSize(m_pEntryFunc) - itr->second->size_ImplicitArgInfoList(); unsigned int explicitArgsNum = IGCLLVM::GetFuncArgSize(m_pEntryFunc) - itr->second->size_ImplicitArgInfoList();
if (pArgument->getArgNo() < explicitArgsNum) 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); KernelArg::ArgType argType = KernelArg::calcArgType(pArgument, typeStr);
FunctionMetaData *funcMD = &modMD->FuncMD[const_cast<Function*>(m_pEntryFunc)]; FunctionMetaData *funcMD = &modMD->FuncMD[const_cast<Function*>(m_pEntryFunc)];
ResourceAllocMD *resourceAlloc = &funcMD->resourceAlloc; ResourceAllocMD *resourceAlloc = &funcMD->resourceAlloc;
......
...@@ -1901,12 +1901,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const llvm::MDNode* pNode, bool hasId ...@@ -1901,12 +1901,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const llvm::MDNode* pNode, bool hasId
m_LocalOffsets(getLocalOffsetsNode(pNode), true), m_LocalOffsets(getLocalOffsetsNode(pNode), true),
m_ResourceAlloc(ResourceAllocMetaData::get(getResourceAllocNode(pNode), true)), m_ResourceAlloc(ResourceAllocMetaData::get(getResourceAllocNode(pNode), true)),
m_OpenCLVectorTypeHint(VectorTypeHintMetaData::get(getOpenCLVectorTypeHintNode(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) m_pNode(pNode)
{} {}
...@@ -1922,12 +1916,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(): m_Type("function_type"), ...@@ -1922,12 +1916,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(): m_Type("function_type"),
m_LocalOffsets("local_offsets"), m_LocalOffsets("local_offsets"),
m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")), m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")),
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")), 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) m_pNode(NULL)
{} {}
...@@ -1944,12 +1932,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const char* name): ...@@ -1944,12 +1932,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const char* name):
m_LocalOffsets("local_offsets"), m_LocalOffsets("local_offsets"),
m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")), m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")),
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")), 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) m_pNode(NULL)
{} {}
...@@ -2006,40 +1988,6 @@ bool FunctionInfoMetaData::hasValue() const ...@@ -2006,40 +1988,6 @@ bool FunctionInfoMetaData::hasValue() const
return true; 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(); return NULL != m_pNode || dirty();
} }
...@@ -2083,30 +2031,6 @@ bool FunctionInfoMetaData::dirty() const ...@@ -2083,30 +2031,6 @@ bool FunctionInfoMetaData::dirty() const
{ {
return true; 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; return false;
} }
...@@ -2123,12 +2047,6 @@ void FunctionInfoMetaData::discardChanges() ...@@ -2123,12 +2047,6 @@ void FunctionInfoMetaData::discardChanges()
m_LocalOffsets.discardChanges(); m_LocalOffsets.discardChanges();
m_ResourceAlloc.discardChanges(); m_ResourceAlloc.discardChanges();
m_OpenCLVectorTypeHint.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 ...@@ -2183,37 +2101,6 @@ llvm::Metadata* FunctionInfoMetaData::generateNode(llvm::LLVMContext& context) c
{ {
args.push_back(m_OpenCLVectorTypeHint.generateNode(context)); 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); return llvm::MDNode::get(context, args);
} }
...@@ -2246,12 +2133,6 @@ void FunctionInfoMetaData::save(llvm::LLVMContext& context, llvm::MDNode* pNode) ...@@ -2246,12 +2133,6 @@ void FunctionInfoMetaData::save(llvm::LLVMContext& context, llvm::MDNode* pNode)
m_LocalOffsets.save(context, llvm::cast<llvm::MDNode>(getLocalOffsetsNode(pNode))); m_LocalOffsets.save(context, llvm::cast<llvm::MDNode>(getLocalOffsetsNode(pNode)));
m_ResourceAlloc.save(context, llvm::cast<llvm::MDNode>(getResourceAllocNode(pNode))); m_ResourceAlloc.save(context, llvm::cast<llvm::MDNode>(getResourceAllocNode(pNode)));
m_OpenCLVectorTypeHint.save(context, llvm::cast<llvm::MDNode>(getOpenCLVectorTypeHintNode(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 llvm::Metadata* FunctionInfoMetaData::getTypeNode( const llvm::MDNode* pParentNode) const
...@@ -2434,114 +2315,6 @@ llvm::MDNode* FunctionInfoMetaData::getOpenCLVectorTypeHintNode( const llvm::MDN ...@@ -2434,114 +2315,6 @@ llvm::MDNode* FunctionInfoMetaData::getOpenCLVectorTypeHintNode( const llvm::MDN
return NULL; 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) static bool isNamedNode(const llvm::Metadata* pNode, const char* name)
{ {
const llvm::MDNode* pMDNode = llvm::dyn_cast<llvm::MDNode>(pNode); const llvm::MDNode* pMDNode = llvm::dyn_cast<llvm::MDNode>(pNode);
......
This diff is collapsed.
...@@ -153,20 +153,22 @@ namespace //Anonymous ...@@ -153,20 +153,22 @@ namespace //Anonymous
class MetadataBuilder class MetadataBuilder
{ {
IGC::IGCMD::MetaDataUtils* _pMdUtils; IGC::IGCMD::MetaDataUtils* _pMdUtils;
IGC::ModuleMetaData* modMD;
DataContext& _dataContext; DataContext& _dataContext;
public: public:
MetadataBuilder(IGC::IGCMD::MetaDataUtils* pMdUtils, DataContext& dataContext) MetadataBuilder(IGC::IGCMD::MetaDataUtils* pMdUtils, DataContext& dataContext, IGC::ModuleMetaData* moduleMD)
: _pMdUtils(pMdUtils), _dataContext(dataContext) {} : modMD(moduleMD), _pMdUtils(pMdUtils), _dataContext(dataContext) {}
/// Return function metadata if function is kernel /// 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)) 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) { bool eraseKernelMetadata(llvm::Function* func, IGC::ModuleMetaData* modMD) {
...@@ -185,21 +187,22 @@ namespace //Anonymous ...@@ -185,21 +187,22 @@ namespace //Anonymous
} }
/// Return kernel argument type name from metadata /// 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); auto funcInfoMD = getOrEmitKernelMetadata(const_cast<llvm::Function*>(func));
assert((funcInfoMD.get() != nullptr) && "cannot get or emit for kernel metadata"); assert((funcInfoMD != nullptr) && "cannot get or emit for kernel metadata");
assert(funcInfoMD->m_OpenCLArgBaseTypes.size() > (unsigned) argNum);
return funcInfoMD->getOpenCLArgBaseTypesItem(argNum); return funcInfoMD->m_OpenCLArgBaseTypes[argNum];
} }
/// Return function metadata if function is kernel, emit new kernel metadata if not. /// 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); 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; return kernelMD;
} }
...@@ -223,7 +226,7 @@ namespace //Anonymous ...@@ -223,7 +226,7 @@ namespace //Anonymous
// Function responsible for emitting special meta data for block dispatcher functions // // 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 // // 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 ...@@ -1193,10 +1196,10 @@ namespace //Anonymous
public: public:
DataContext(IGC::IGCMD::MetaDataUtils* pMdUtils) DataContext(IGC::ModuleMetaData* modMD, IGC::IGCMD::MetaDataUtils* pMdUtils)
: _blocksNum(0) : _blocksNum(0)
, _kindQuery(*this) , _kindQuery(*this)
, _MDBuilder(pMdUtils, *this) , _MDBuilder(pMdUtils, *this, modMD)
{} {}
const KindQuery& getKindQuery() { return _kindQuery; } const KindQuery& getKindQuery() { return _kindQuery; }
...@@ -1289,7 +1292,7 @@ namespace //Anonymous ...@@ -1289,7 +1292,7 @@ namespace //Anonymous
auto modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData(); auto modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();
// dataContext "owns" all created objects in internal "database" // 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 // Inline functions which have device exec calls up to kernel or block_invoke level
// to properly resolve parent argument number for the following case: // to properly resolve parent argument number for the following case:
...@@ -1608,7 +1611,7 @@ namespace //Anonymous ...@@ -1608,7 +1611,7 @@ namespace //Anonymous
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
// MetadataBuilder implementation // MetadataBuilder implementation
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
IGC::IGCMD::FunctionInfoMetaDataHandle MetadataBuilder::EmitKernelMetadata(const llvm::Function* kernelFunc) void MetadataBuilder::EmitKernelMetadata(const llvm::Function* kernelFunc)
{ {
// Helper structure for pretty printing types // Helper structure for pretty printing types
struct TypeNameHelper { struct TypeNameHelper {
...@@ -1670,11 +1673,13 @@ namespace //Anonymous ...@@ -1670,11 +1673,13 @@ namespace //Anonymous
//link dispatchMd to dispatch kernel //link dispatchMd to dispatch kernel
IGC::IGCMD::FunctionInfoMetaDataHandle dispatchMd = _pMdUtils->getOrInsertFunctionsInfoItem(const_cast<llvm::Function*>(kernelFunc)); IGC::IGCMD::FunctionInfoMetaDataHandle dispatchMd = _pMdUtils->getOrInsertFunctionsInfoItem(const_cast<llvm::Function*>(kernelFunc));
auto funcMD = &modMD->FuncMD[const_cast<llvm::Function*>(kernelFunc)];//insert if not present