Skip to content

Commit 5981325

Browse files
lfilipkoigcbot
authored andcommitted
Minor source code refactoring: move FixAddressSpaceInAllUses() to helper file.
Private memory resolution minor refactoring: convert int64 directly to pointer to allocated type.
1 parent 245ef55 commit 5981325

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

IGC/Compiler/CISACodeGen/helper.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,4 +2454,30 @@ namespace IGC
24542454

24552455
return ProcessedType;
24562456
}
2457+
2458+
// Function modifies address space in selected uses of given input value
2459+
void FixAddressSpaceInAllUses(llvm::Value* ptr, uint newAS, uint oldAS)
2460+
{
2461+
IGC_ASSERT(newAS != oldAS);
2462+
2463+
for (auto UI = ptr->user_begin(), E = ptr->user_end(); UI != E; ++UI)
2464+
{
2465+
Instruction* inst = dyn_cast<Instruction>(*UI);
2466+
PointerType* instType = nullptr;
2467+
if (isa<BitCastInst>(inst) || isa<GetElementPtrInst>(inst) ||
2468+
isa<AddrSpaceCastInst>(inst) || isa<PHINode>(inst))
2469+
{
2470+
instType = dyn_cast<PointerType>(inst->getType());
2471+
}
2472+
2473+
if (instType && instType->getAddressSpace() == oldAS)
2474+
{
2475+
Type* eltType = instType->getElementType();
2476+
PointerType* ptrType = PointerType::get(eltType, newAS);
2477+
inst->mutateType(ptrType);
2478+
FixAddressSpaceInAllUses(inst, newAS, oldAS);
2479+
}
2480+
}
2481+
}
2482+
24572483
} // namespace IGC

IGC/Compiler/CISACodeGen/helper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,7 @@ namespace IGC
471471

472472
// Return base type of complex type or nullptr if it cannot be processed
473473
llvm::Type* GetBaseType(llvm::Type* ProcessedType);
474+
475+
// Function modifies address space in selected uses of given input value
476+
void FixAddressSpaceInAllUses(llvm::Value* ptr, uint newAS, uint oldAS);
474477
} // namespace IGC

IGC/Compiler/FixResourcePtr.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,6 @@ bool FixResourcePtr::runOnFunction(llvm::Function& F)
8989
return m_changed;
9090
}
9191

92-
93-
// Function modifies address space in all BitCast or GEP uses input pointer.
94-
void FixResourcePtr::FixAddressSpaceInAllUses(Value* ptr, uint newAS, uint oldAS)
95-
{
96-
IGC_ASSERT(newAS != oldAS);
97-
98-
for (auto UI = ptr->user_begin(), E = ptr->user_end(); UI != E; ++UI)
99-
{
100-
Instruction* inst = dyn_cast<Instruction>(*UI);
101-
PointerType* instType = nullptr;
102-
if (BitCastInst * bitCastInst = dyn_cast<BitCastInst>(inst))
103-
{
104-
instType = dyn_cast<PointerType>(bitCastInst->getType());
105-
}
106-
else if (GetElementPtrInst * gepInst = dyn_cast<GetElementPtrInst>(inst))
107-
{
108-
instType = dyn_cast<PointerType>(gepInst->getType());
109-
}
110-
111-
if (instType && instType->getAddressSpace() == oldAS)
112-
{
113-
Type* eltType = instType->getElementType();
114-
PointerType* ptrType = PointerType::get(eltType, newAS);
115-
inst->mutateType(ptrType);
116-
FixAddressSpaceInAllUses(inst, newAS, oldAS);
117-
}
118-
}
119-
}
120-
12192
void FixResourcePtr::RemoveGetBufferPtr(GenIntrinsicInst* bufPtr, Value* bufIdx)
12293
{
12394
uint outAS = bufPtr->getType()->getPointerAddressSpace();

IGC/Compiler/FixResourcePtr.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ namespace IGC
6363

6464
llvm::Value* CreateStoreIntrinsic(llvm::StoreInst* inst, llvm::Instruction* bufPtr, llvm::Value* offsetVal);
6565

66-
void FixAddressSpaceInAllUses(llvm::Value* ptr, uint newAS, uint oldAS);
67-
6866
/// @brief Indicates if the pass changed the processed function
6967
bool m_changed;
7068
/// Function we are processing

IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ bool PrivateMemoryResolution::resolveAllocaInstructions(bool privateOnStack)
943943
Value* totalOffset = builder.CreateAdd(bufferOffset, perLaneOffset, VALUE_NAME(pAI->getName() + ".totalOffset"));
944944
totalOffset = builder.CreateZExt(totalOffset, privateBase->getType());
945945
Value* threadOffset = builder.CreateAdd(privateBase, totalOffset, VALUE_NAME(pAI->getName() + ".threadOffset"));
946-
Value* privateBufferPTR = builder.CreateIntToPtr(threadOffset, Type::getInt8Ty(C)->getPointerTo(scratchMemoryAddressSpace), VALUE_NAME(pAI->getName() + ".privateBufferPTR"));
946+
Value* privateBufferPTR = builder.CreateIntToPtr(threadOffset, pAI->getAllocatedType()->getPointerTo(scratchMemoryAddressSpace), VALUE_NAME(pAI->getName() + ".privateBufferPTR"));
947947
Value* privateBuffer = builder.CreatePointerCast(privateBufferPTR, pAI->getType(), VALUE_NAME(pAI->getName() + ".privateBuffer"));
948948

949949
if (TransposeMemLayout)
@@ -957,6 +957,7 @@ bool PrivateMemoryResolution::resolveAllocaInstructions(bool privateOnStack)
957957
// Replace all uses of original alloca with the bitcast
958958
pAI->replaceAllUsesWith(privateBuffer);
959959
pAI->eraseFromParent();
960+
960961
}
961962

962963
return true;

0 commit comments

Comments
 (0)