Skip to content

Commit 0f0eb32

Browse files
jgu222pszymich
authored andcommitted
Caching layout struct types
LdStCombine is a function pass. Previously, the newly-created layout struct types are searched by invoking Module's getIdentifiedStructTypes(), so that struct types, created from the previous functions, can be reused whenever possible. But getIdentifiedStructTypes() is costly. Thus, there, we caching struct types in codegencontext for reuse. (cherry picked from commit de5dc9e)
1 parent a8c3402 commit 0f0eb32

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

IGC/Compiler/CISACodeGen/MemOpt.cpp

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,8 +2573,6 @@ namespace {
25732573
bool getAddressDiffIfConstant(Instruction* I0, Instruction* I1, int64_t& ConstBO);
25742574

25752575
// Create unique identified struct type
2576-
SmallVector<StructType*, 16> m_allLayoutStructTypes;
2577-
void initLayoutStructType(Module* M);
25782576
StructType* getOrCreateUniqueIdentifiedStructType(
25792577
ArrayRef<Type*> EltTys, bool IsSOA, bool IsPacked = true);
25802578

@@ -2588,7 +2586,6 @@ namespace {
25882586
m_visited.clear();
25892587
m_instOrder.clear();
25902588
m_bundles.clear();
2591-
m_allLayoutStructTypes.clear();
25922589
}
25932590
};
25942591
}
@@ -2773,8 +2770,6 @@ bool LdStCombine::runOnFunction(Function& F)
27732770
}
27742771
m_F = &F;
27752772

2776-
initLayoutStructType(m_F->getParent());
2777-
27782773
// Initialize symbolic evaluation
27792774
m_symEval.setDataLayout(m_DL);
27802775

@@ -3397,23 +3392,6 @@ void LdStCombine::mergeConstElements(
33973392
EltVals.insert(EltVals.end(), mergedElts.begin(), mergedElts.end());
33983393
}
33993394

3400-
// Get all layout struct types created already for different functions in
3401-
// the same module.
3402-
//
3403-
// This is for creating unique struct layout type per module. Layout
3404-
// struct type is identified, but if two identified layout structs are
3405-
// the same layout, they are the same.
3406-
void LdStCombine::initLayoutStructType(Module* M)
3407-
{
3408-
auto modAllNamedStructTys = M->getIdentifiedStructTypes();
3409-
for (auto II : modAllNamedStructTys) {
3410-
StructType* stTy = II;
3411-
if (isLayoutStructType(stTy)) {
3412-
m_allLayoutStructTypes.push_back(stTy);
3413-
}
3414-
}
3415-
}
3416-
34173395
// This is to make sure to reuse the layout types. Two identified structs have
34183396
// the same layout if
34193397
// 1. both are SOA or both are AOS; and
@@ -3422,7 +3400,8 @@ void LdStCombine::initLayoutStructType(Module* M)
34223400
StructType* LdStCombine::getOrCreateUniqueIdentifiedStructType(
34233401
ArrayRef<Type*> EltTys, bool IsSOA, bool IsPacked)
34243402
{
3425-
for (auto II : m_allLayoutStructTypes) {
3403+
auto& layoutStructTypes = m_CGC->getLayoutStructTypes();
3404+
for (auto II : layoutStructTypes) {
34263405
StructType* stTy = II;
34273406
if (IsPacked == stTy->isPacked() &&
34283407
IsSOA == isLayoutStructTypeSOA(stTy) &&
@@ -3434,7 +3413,7 @@ StructType* LdStCombine::getOrCreateUniqueIdentifiedStructType(
34343413
StructType* StTy = StructType::create(EltTys,
34353414
IsSOA ? getStructNameForSOALayout() : getStructNameForAOSLayout(),
34363415
IsPacked);
3437-
m_allLayoutStructTypes.push_back(StTy);
3416+
layoutStructTypes.push_back(StTy);
34383417
return StTy;
34393418
}
34403419

IGC/Compiler/CodeGenPublic.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,8 @@ namespace IGC
849849
SafeIntrinsicIDCacheTy m_SafeIntrinsicIDCache;
850850
/// metadata caching
851851
UserAddrSpaceMD m_UserAddrSpaceMD;
852+
// structType caching : for unique identified struct type
853+
llvm::SmallVector<llvm::StructType*, 16> m_allLayoutStructTypes;
852854
void AddRef();
853855
void Release();
854856
};
@@ -1101,6 +1103,10 @@ namespace IGC
11011103
IGC_ASSERT(llvmCtxWrapper);
11021104
return llvmCtxWrapper->m_UserAddrSpaceMD;
11031105
}
1106+
llvm::SmallVector<llvm::StructType*, 16>& getLayoutStructTypes() {
1107+
IGC_ASSERT(llvmCtxWrapper);
1108+
return llvmCtxWrapper->m_allLayoutStructTypes;
1109+
}
11041110

11051111
unsigned int GetSIMDInfoOffset(SIMDMode simd, ShaderDispatchMode mode)
11061112
{

0 commit comments

Comments
 (0)