@@ -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
118129void 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 }
0 commit comments