Commit 0c929550 authored by Rishipal Singh Bhatia's avatar Rishipal Singh Bhatia Committed by gbsbuild

IGC refactor to move the LocalOffsets metaata to new frameowrk

Change-Id: I74a07fb5f768c80f7f4d937f2ef528a6e5fa1d06
parent bf992646
......@@ -275,13 +275,19 @@ bool GenIRLowering::runOnFunction(Function &F) {
// Replace SLM PtrToInt by the assigned immed offset
// Later optimization (InstCombine) can fold away some address computation
for (auto LOI = FII->second->begin_LocalOffsets(),
LOE = FII->second->end_LocalOffsets();
LOI != LOE; ++LOI) {
IGCMD::LocalOffsetMetaDataHandle LH = *LOI;
FunctionMetaData* funcMD = &modMD->FuncMD[&F];
for (auto localOffetsItr = funcMD->localOffsets.begin(), localOffsetsEnd = funcMD->localOffsets.end();
localOffetsItr != localOffsetsEnd;
++localOffetsItr)
{
LocalOffsetMD localOffset = *localOffetsItr;
// look up the value-to-offset mapping
Value *V = LH->getVar();
unsigned Offset = LH->getOffset();
Value *V = localOffset.m_Var;
unsigned Offset = localOffset.m_Offset;
// Skip non-pointer values.
if (!V->getType()->isPointerTy())
continue;
......
......@@ -227,16 +227,18 @@ void COpenCLKernel::PreCompile()
RecomputeBTLayout();
ModuleMetaData* modMD = m_Context->getModuleMetaData();
auto funcIter = modMD->FuncMD.find(entry);
// Initialize the table of offsets for GlobalVariables representing locals
auto funcIter = m_pMdUtils->findFunctionsInfoItem(entry);
if (funcIter != m_pMdUtils->end_FunctionsInfo())
if (funcIter != modMD->FuncMD.end())
{
auto loIter = funcIter->second->begin_LocalOffsets();
auto loEnd = funcIter->second->end_LocalOffsets();
auto loIter = funcIter->second.localOffsets.begin();
auto loEnd = funcIter->second.localOffsets.end();
for (; loIter != loEnd; ++loIter)
{
LocalOffsetMetaDataHandle loHandle = *loIter;
m_localOffsetsMap[loHandle->getVar()] = loHandle->getOffset();
LocalOffsetMD loHandle = *loIter;
m_localOffsetsMap[loHandle.m_Var] = loHandle.m_Offset;
}
}
}
......
......@@ -284,134 +284,6 @@ llvm::Metadata* ArgInfoMetaData::getImgAccessIntCoordsNode( const llvm::MDNode*
return NULL;
}
///
// Ctor - loads the LocalOffsetMetaData from the given metadata node
//
LocalOffsetMetaData::LocalOffsetMetaData(const llvm::MDNode* pNode, bool hasId):
_Mybase(pNode, hasId),
m_Var(getVarNode(pNode)),
m_Offset(getOffsetNode(pNode)),
m_pNode(pNode)
{}
///
// Default Ctor - creates the empty, not named LocalOffsetMetaData object
//
LocalOffsetMetaData::LocalOffsetMetaData():
m_pNode(NULL)
{}
///
// Ctor - creates the empty, named LocalOffsetMetaData object
//
LocalOffsetMetaData::LocalOffsetMetaData(const char* name):
_Mybase(name),
m_pNode(NULL)
{}
bool LocalOffsetMetaData::hasValue() const
{
if (m_Var.hasValue())
{
return true;
}
if (m_Offset.hasValue())
{
return true;
}
return NULL != m_pNode || dirty();
}
///
// Returns true if any of the LocalOffsetMetaData`s members has changed
bool LocalOffsetMetaData::dirty() const
{
if( m_Var.dirty() )
{
return true;
}
if( m_Offset.dirty() )
{
return true;
}
return false;
}
///
// Discards the changes done to the LocalOffsetMetaData instance
void LocalOffsetMetaData::discardChanges()
{
m_Var.discardChanges();
m_Offset.discardChanges();
}
///
// Generates the new MDNode hierarchy for the given structure
llvm::Metadata* LocalOffsetMetaData::generateNode(llvm::LLVMContext& context) const
{
llvm::SmallVector<llvm::Metadata*, 5> args;
llvm::Metadata* pIDNode = _Mybase::generateNode(context);
if( NULL != pIDNode )
{
args.push_back(pIDNode);
}
args.push_back( m_Var.generateNode(context));
args.push_back( m_Offset.generateNode(context));
return llvm::MDNode::get(context, args);
}
///
// Saves the structure changes to the given MDNode
void LocalOffsetMetaData::save(llvm::LLVMContext& context, llvm::MDNode* pNode) const
{
assert( pNode && "The target node should be valid pointer");
// we assume that underlying metadata node has not changed under our foot
if( pNode == m_pNode && !dirty() )
{
return;
}
#if 0
// check that we could save the new information to the given node without regenerating it
if( !compatibleWith(pNode) )
{
pNode->replaceAllUsesWith(generateNode(context));
return;
}
#endif
m_Var.save(context, llvm::cast<llvm::MDNode>(getVarNode(pNode)));
m_Offset.save(context, llvm::cast<llvm::MDNode>(getOffsetNode(pNode)));
}
llvm::Metadata* LocalOffsetMetaData::getVarNode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
{
return NULL;
}
unsigned int offset = _Mybase::getStartIndex();
return pParentNode->getOperand(0 + offset).get();
}
llvm::Metadata* LocalOffsetMetaData::getOffsetNode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
{
return NULL;
}
unsigned int offset = _Mybase::getStartIndex();
return pParentNode->getOperand(1 + offset).get();
}
///
// Ctor - loads the ArgDependencyInfoMetaData from the given metadata node
//
......@@ -1112,7 +984,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const llvm::MDNode* pNode, bool hasId
m_ThreadGroupSize(ThreadGroupSizeMetaData::get(getThreadGroupSizeNode(pNode), true)),
m_ThreadGroupSizeHint(ThreadGroupSizeMetaData::get(getThreadGroupSizeHintNode(pNode), true)),
m_SubGroupSize(SubGroupSizeMetaData::get(getSubGroupSizeNode(pNode), true)),
m_LocalOffsets(getLocalOffsetsNode(pNode), true),
m_OpenCLVectorTypeHint(VectorTypeHintMetaData::get(getOpenCLVectorTypeHintNode(pNode), true)),
m_pNode(pNode)
{}
......@@ -1127,6 +998,7 @@ FunctionInfoMetaData::FunctionInfoMetaData(): m_Type("function_type"),
m_ThreadGroupSizeHint(ThreadGroupSizeMetaDataHandle::ObjectType::get("thread_group_size_hint")),
m_SubGroupSize(SubGroupSizeMetaDataHandle::ObjectType::get("sub_group_size")),
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")),
m_pNode(NULL)
{}
......@@ -1140,7 +1012,7 @@ FunctionInfoMetaData::FunctionInfoMetaData(const char* name):
m_ThreadGroupSize(ThreadGroupSizeMetaDataHandle::ObjectType::get("thread_group_size")),
m_ThreadGroupSizeHint(ThreadGroupSizeMetaDataHandle::ObjectType::get("thread_group_size_hint")),
m_SubGroupSize(SubGroupSizeMetaDataHandle::ObjectType::get("sub_group_size")),
m_LocalOffsets("local_offsets"),
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")),
m_pNode(NULL)
{}
......@@ -1180,13 +1052,9 @@ bool FunctionInfoMetaData::hasValue() const
if (m_SubGroupSize->hasValue())
{
return true;
}
if (m_LocalOffsets.hasValue())
{
return true;
}
}
if (m_OpenCLVectorTypeHint->hasValue())
{
......@@ -1223,11 +1091,7 @@ bool FunctionInfoMetaData::dirty() const
if( m_SubGroupSize.dirty() )
{
return true;
}
if( m_LocalOffsets.dirty() )
{
return true;
}
}
if( m_OpenCLVectorTypeHint.dirty() )
{
return true;
......@@ -1245,7 +1109,6 @@ void FunctionInfoMetaData::discardChanges()
m_ThreadGroupSize.discardChanges();
m_ThreadGroupSizeHint.discardChanges();
m_SubGroupSize.discardChanges();
m_LocalOffsets.discardChanges();
m_OpenCLVectorTypeHint.discardChanges();
}
......@@ -1287,11 +1150,6 @@ llvm::Metadata* FunctionInfoMetaData::generateNode(llvm::LLVMContext& context) c
args.push_back(m_SubGroupSize.generateNode(context));
}
if (isLocalOffsetsHasValue())
{
args.push_back(m_LocalOffsets.generateNode(context));
}
if (m_OpenCLVectorTypeHint->hasValue())
{
args.push_back(m_OpenCLVectorTypeHint.generateNode(context));
......@@ -1453,25 +1311,7 @@ llvm::Metadata* FunctionInfoMetaData::getLocalSizeNode( const llvm::MDNode* pPar
}
return NULL;
}
llvm::MDNode* FunctionInfoMetaData::getLocalOffsetsNode( 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(), "local_offsets") )
{
return llvm::dyn_cast<llvm::MDNode>(i.get());
}
}
return NULL;
}
llvm::MDNode* FunctionInfoMetaData::getOpenCLVectorTypeHintNode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
......
......@@ -36,9 +36,6 @@ namespace IGC { namespace IGCMD
//typedefs and forward declarations
class ArgInfoMetaData;
typedef MetaObjectHandle<ArgInfoMetaData> ArgInfoMetaDataHandle;
class LocalOffsetMetaData;
typedef MetaObjectHandle<LocalOffsetMetaData> LocalOffsetMetaDataHandle;
class SubGroupSizeMetaData;
typedef MetaObjectHandle<SubGroupSizeMetaData> SubGroupSizeMetaDataHandle;
......@@ -61,9 +58,6 @@ typedef MetaObjectHandle<FunctionInfoMetaData> FunctionInfoMetaDataHandle;
typedef MetaDataList<ArgInfoMetaDataHandle> ArgInfoListMetaDataList;
typedef MetaObjectHandle<ArgInfoListMetaDataList> ArgInfoListMetaDataListHandle;
typedef MetaDataList<LocalOffsetMetaDataHandle> LocalOffsetsMetaDataList;
typedef MetaObjectHandle<LocalOffsetsMetaDataList> LocalOffsetsMetaDataListHandle;
typedef MetaDataList<PointerProgramBinaryInfoMetaDataHandle> PointerProgramBinaryInfosMetaDataList;
typedef MetaObjectHandle<PointerProgramBinaryInfosMetaDataList> PointerProgramBinaryInfosMetaDataListHandle;
......@@ -245,127 +239,6 @@ private:
const llvm::MDNode* m_pNode;
};
///
// Read/Write the LocalOffset structure from/to LLVM metadata
//
class LocalOffsetMetaData:public IMetaDataObject
{
public:
typedef LocalOffsetMetaData _Myt;
typedef IMetaDataObject _Mybase;
// typedefs for data member types
typedef MetaDataValue<llvm::GlobalVariable>::value_type VarType;
typedef MetaDataValue<int32_t>::value_type OffsetType;
public:
///
// Factory method - creates the LocalOffsetMetaData from the given metadata node
//
static _Myt* get(const llvm::MDNode* pNode, bool hasId = false)
{
return new _Myt(pNode, hasId);
}
///
// Factory method - create the default empty LocalOffsetMetaData object
static _Myt* get()
{
return new _Myt();
}
///
// Factory method - create the default empty named LocalOffsetMetaData object
static _Myt* get(const char* name)
{
return new _Myt(name);
}
///
// Ctor - loads the LocalOffsetMetaData from the given metadata node
//
LocalOffsetMetaData(const llvm::MDNode* pNode, bool hasId);
///
// Default Ctor - creates the empty, not named LocalOffsetMetaData object
//
LocalOffsetMetaData();
///
// Ctor - creates the empty, named LocalOffsetMetaData object
//
LocalOffsetMetaData(const char* name);
/// Var related methods
VarType getVar() const
{
return m_Var.get();
}
void setVar( const VarType& val)
{
m_Var.set(val);
}
bool isVarHasValue() const
{
return m_Var.hasValue();
}
/// Offset related methods
OffsetType getOffset() const
{
return m_Offset.get();
}
void setOffset( const OffsetType& val)
{
m_Offset.set(val);
}
bool isOffsetHasValue() const
{
return m_Offset.hasValue();
}
///
// Returns true if any of the LocalOffsetMetaData`s members has changed
bool dirty() const;
///
// Returns true if the structure was loaded from the metadata or was changed
bool hasValue() const;
///
// Discards the changes done to the LocalOffsetMetaData instance
void discardChanges();
///
// Generates the new MDNode hierarchy for the given structure
llvm::Metadata* generateNode(llvm::LLVMContext& context) const;
///
// Saves the structure changes to the given MDNode
void save(llvm::LLVMContext& context, llvm::MDNode* pNode) const;
private:
///
// Returns true if the given MDNode could be saved to without replacement
bool compatibleWith( const llvm::MDNode* pNode) const
{
return false;
}
private:
typedef MetaDataIterator<llvm::MDNode> NodeIterator;
llvm::Metadata* getVarNode( const llvm::MDNode* pParentNode) const;
llvm::Metadata* getOffsetNode( const llvm::MDNode* pParentNode) const;
private:
// data members
MetaDataValue<llvm::GlobalVariable> m_Var;
MetaDataValue<int32_t> m_Offset;
// parent node
const llvm::MDNode* m_pNode;
};
///
// Read/Write the ArgDependencyInfo structure from/to LLVM metadata
//
......@@ -1019,9 +892,6 @@ public:
typedef NamedMetaDataValue<int32_t>::value_type TypeType;
typedef MetaDataList<ArgInfoMetaDataHandle> ArgInfoListList;
typedef MetaDataList<ArgInfoMetaDataHandle> ImplicitArgInfoListList;
typedef MetaDataList<LocalOffsetMetaDataHandle> LocalOffsetsList;
typedef NamedMetaDataValue<int32_t>::value_type PrivateMemoryPerWIType;
typedef NamedMetaDataValue<int32_t>::value_type NeedBindlessHandleType;
......@@ -1223,65 +1093,6 @@ public:
return m_SubGroupSize;
}
/// LocalOffsets related methods
LocalOffsetsList::iterator begin_LocalOffsets()
{
return m_LocalOffsets.begin();
}
LocalOffsetsList::iterator end_LocalOffsets()
{
return m_LocalOffsets.end();
}
LocalOffsetsList::const_iterator begin_LocalOffsets() const
{
return m_LocalOffsets.begin();
}
LocalOffsetsList::const_iterator end_LocalOffsets() const
{
return m_LocalOffsets.end();
}
size_t size_LocalOffsets() const
{
return m_LocalOffsets.size();
}
bool empty_LocalOffsets() const
{
return m_LocalOffsets.empty();
}
bool isLocalOffsetsHasValue() const
{
return m_LocalOffsets.hasValue();
}
LocalOffsetsList::item_type getLocalOffsetsItem( size_t index ) const
{
return m_LocalOffsets.getItem(index);
}
void clearLocalOffsets()
{
m_LocalOffsets.clear();
}
void setLocalOffsetsItem( size_t index, const LocalOffsetsList::item_type& item )
{
return m_LocalOffsets.setItem(index, item);
}
void addLocalOffsetsItem(const LocalOffsetsList::item_type& val)
{
m_LocalOffsets.push_back(val);
}
LocalOffsetsList::iterator eraseLocalOffsetsItem(LocalOffsetsList::iterator i)
{
return m_LocalOffsets.erase(i);
}
/// OpenCLVectorTypeHint related methods
VectorTypeHintMetaDataHandle getOpenCLVectorTypeHint()
......@@ -1328,7 +1139,6 @@ private:
llvm::MDNode* getSubGroupSizeNode( const llvm::MDNode* pParentNode) const;
llvm::MDNode* getWorkgroupWalkOrderNode(const llvm::MDNode* pParentNode) const;
llvm::Metadata* getLocalSizeNode( const llvm::MDNode* pParentNode) const;
llvm::MDNode* getLocalOffsetsNode( const llvm::MDNode* pParentNode) const;
llvm::MDNode* getOpenCLVectorTypeHintNode( const llvm::MDNode* pParentNode) const;
private:
......@@ -1339,7 +1149,7 @@ private:
ThreadGroupSizeMetaDataHandle m_ThreadGroupSize;
ThreadGroupSizeMetaDataHandle m_ThreadGroupSizeHint;
SubGroupSizeMetaDataHandle m_SubGroupSize;
MetaDataList<LocalOffsetMetaDataHandle> m_LocalOffsets;
VectorTypeHintMetaDataHandle m_OpenCLVectorTypeHint;
// parent node
const llvm::MDNode* m_pNode;
......
......@@ -112,7 +112,7 @@ static bool useAsPointerOnly(Value *V) {
bool InlineLocalsResolution::runOnModule(Module &M)
{
MetaDataUtils *pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
ModuleMetaData *modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();
// Compute the offset of each inline local in the kernel,
// and their total size.
std::map<Function*, unsigned int> sizeMap;
......@@ -178,10 +178,11 @@ bool InlineLocalsResolution::runOnModule(Module &M)
auto NewPtr = ConstantExpr::getBitCast(ExtSLM, arg->getType());
arg->replaceAllUsesWith(NewPtr);
// Update MD.
LocalOffsetMetaDataHandle lo = LocalOffsetMetaDataHandle(LocalOffsetMetaData::get());
lo->setVar(ExtSLM);
lo->setOffset(Offset);
pMdUtils->getFunctionsInfoItem(pFunc)->addLocalOffsetsItem(lo);
LocalOffsetMD localOffset;
localOffset.m_Var = ExtSLM;
localOffset.m_Offset = Offset;
modMD->FuncMD[pFunc].localOffsets.push_back(localOffset);
IGC::appendToUsed(M, ExtSLM);
IsFirstSLMArgument = false;
} else {
......@@ -449,13 +450,14 @@ void InlineLocalsResolution::computeOffsetList(Module& M, std::map<Function*, un
// And now the offsets.
for (auto offsetIter = offsetMap[iter->first].begin(), offsetEnd = offsetMap[iter->first].end(); offsetIter != offsetEnd; ++offsetIter)
{
LocalOffsetMetaDataHandle lo = LocalOffsetMetaDataHandle(LocalOffsetMetaData::get());
unsigned Offset = offsetIter->second;
if (!useAsPointerOnly(offsetIter->first))
Offset |= VALID_LOCAL_HIGH_BITS;
lo->setVar(offsetIter->first);
lo->setOffset(Offset);
pMdUtils->getFunctionsInfoItem(iter->first)->addLocalOffsetsItem(lo);
LocalOffsetMD localOffset;
localOffset.m_Var = offsetIter->first;
localOffset.m_Offset = Offset;
modMD->FuncMD[iter->first].localOffsets.push_back(localOffset);
}
}
pMdUtils->save(M.getContext());
......
......@@ -81,6 +81,12 @@ namespace IGC
int numChannelsUsed = 0;
};
struct LocalOffsetMD
{
int m_Offset;
llvm::GlobalVariable* m_Var;
};
struct WorkGroupWalkOrderMD
{
int dim0 = 0;
......@@ -99,6 +105,7 @@ namespace IGC
//to hold metadata of every function
struct FunctionMetaData
{
std::vector<LocalOffsetMD> localOffsets;
WorkGroupWalkOrderMD workGroupWalkOrder;
std::vector<FuncArgMD> funcArgs;
FunctionTypeMD functionType = UnknownFunction;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment