Skip to content

Commit 71d1380

Browse files
itsimbalsys_zuul
authored andcommitted
The transformation in PromoteStatelessToBindless is performed for
all users of found buffer argument but there are places where such transformation is illegal. The idea is to collect only instructions which are related to an access (load/store) through the buffer and make the transformation for collected instructions only. Change-Id: I7344a3d5ec6a04fa91835b5b0b8490683826a37b
1 parent 077cf81 commit 71d1380

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

IGC/Compiler/PromoteStatelessToBindless.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ void PromoteStatelessToBindless::GetAccessInstToSrcPointerMap(Instruction* inst,
101101
return;
102102
}
103103

104-
Value* srcPtr = IGC::TracePointerSource(resourcePtr);
104+
std::vector<Value*> tempList;
105+
Value* srcPtr = IGC::TracePointerSource(resourcePtr, false, true, true, tempList);
105106

106107
if (!srcPtr ||
107108
!srcPtr->getType()->isPointerTy() ||
@@ -111,31 +112,41 @@ void PromoteStatelessToBindless::GetAccessInstToSrcPointerMap(Instruction* inst,
111112
IGC_ASSERT_MESSAGE(0, "Stateless buffer pointer not traceable, cannot promote stateless to bindless");
112113
return;
113114
}
114-
115+
// Save the instruction, which makes access (load/store/intrinsic) to the buffer
115116
m_AccessToSrcPtrMap[inst] = srcPtr;
117+
// Save the instruction, which generate an address of the buffer. This is the
118+
// instruction right before the last one. The last one has to be the buffer itself.
119+
if (tempList.size() > 1)
120+
{
121+
m_AddressUsedSrcPtrMap[tempList[tempList.size()-2]] = srcPtr;
122+
}
123+
else
124+
{
125+
m_AddressUsedSrcPtrMap[inst] = srcPtr;
126+
}
116127
}
117128

118129
void PromoteStatelessToBindless::PromoteStatelessToBindlessBuffers(Function& F) const
119130
{
120131
ModuleMetaData* modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();
121-
for (auto inst : m_AccessToSrcPtrMap)
132+
// Modify the reference to the buffer not through all users but only in instructions
133+
// which are used in accesing (load/store) the buffer.
134+
for (auto inst : m_AddressUsedSrcPtrMap)
122135
{
136+
Instruction* accessInst = cast<Instruction>(inst.first);
123137
Argument* srcPtr = cast<Argument>(inst.second);
124-
if (!srcPtr->use_empty())
138+
Value* nullSrcPtr = ConstantPointerNull::get(cast<PointerType>(srcPtr->getType()));
139+
accessInst->replaceUsesOfWith(srcPtr, nullSrcPtr);
140+
if (modMD->FuncMD.find(&F) != modMD->FuncMD.end())
125141
{
126-
Value* nullSrcPtr = ConstantPointerNull::get(cast<PointerType>(srcPtr->getType()));
127-
srcPtr->replaceAllUsesWith(nullSrcPtr);
128-
if (modMD->FuncMD.find(&F) != modMD->FuncMD.end())
142+
FunctionMetaData* funcMD = &modMD->FuncMD[&F];
143+
ResourceAllocMD* resourceAlloc = &funcMD->resAllocMD;
144+
ArgAllocMD* argInfo = &resourceAlloc->argAllocMDList[srcPtr->getArgNo()];
145+
IGC_ASSERT_MESSAGE((size_t)srcPtr->getArgNo() < resourceAlloc->argAllocMDList.size(), "ArgAllocMD List Out of Bounds");
146+
if (argInfo->type == ResourceTypeEnum::UAVResourceType)
129147
{
130-
FunctionMetaData* funcMD = &modMD->FuncMD[&F];
131-
ResourceAllocMD* resourceAlloc = &funcMD->resAllocMD;
132-
ArgAllocMD* argInfo = &resourceAlloc->argAllocMDList[srcPtr->getArgNo()];
133-
IGC_ASSERT_MESSAGE((size_t)srcPtr->getArgNo() < resourceAlloc->argAllocMDList.size(), "ArgAllocMD List Out of Bounds");
134-
if (argInfo->type == ResourceTypeEnum::UAVResourceType)
135-
{
136-
// Update metadata to show bindless resource type
137-
argInfo->type = ResourceTypeEnum::BindlessUAVResourceType;
138-
}
148+
// Update metadata to show bindless resource type
149+
argInfo->type = ResourceTypeEnum::BindlessUAVResourceType;
139150
}
140151
}
141152
}

IGC/Compiler/PromoteStatelessToBindless.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace IGC
6363
void PromoteStatelessToBindlessBuffers(llvm::Function& F) const;
6464

6565
std::unordered_map<llvm::Value*, llvm::Value*> m_AccessToSrcPtrMap;
66+
std::unordered_map<llvm::Value*, llvm::Value*> m_AddressUsedSrcPtrMap;
6667
};
6768

6869
} // namespace IGC

0 commit comments

Comments
 (0)