Skip to content

Commit

Permalink
Caching layout struct types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgu222 authored and igcbot committed Oct 14, 2023
1 parent 4a329f7 commit de5dc9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
27 changes: 3 additions & 24 deletions IGC/Compiler/CISACodeGen/MemOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2561,8 +2561,6 @@ namespace {
bool getAddressDiffIfConstant(Instruction* I0, Instruction* I1, int64_t& ConstBO);

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

Expand All @@ -2576,7 +2574,6 @@ namespace {
m_visited.clear();
m_instOrder.clear();
m_bundles.clear();
m_allLayoutStructTypes.clear();
}
};
}
Expand Down Expand Up @@ -2799,8 +2796,6 @@ bool LdStCombine::runOnFunction(Function& F)
}
m_F = &F;

initLayoutStructType(m_F->getParent());

// Initialize symbolic evaluation
m_symEval.setDataLayout(m_DL);

Expand Down Expand Up @@ -3423,23 +3418,6 @@ void LdStCombine::mergeConstElements(
EltVals.insert(EltVals.end(), mergedElts.begin(), mergedElts.end());
}

// Get all layout struct types created already for different functions in
// the same module.
//
// This is for creating unique struct layout type per module. Layout
// struct type is identified, but if two identified layout structs are
// the same layout, they are the same.
void LdStCombine::initLayoutStructType(Module* M)
{
auto modAllNamedStructTys = M->getIdentifiedStructTypes();
for (auto II : modAllNamedStructTys) {
StructType* stTy = II;
if (isLayoutStructType(stTy)) {
m_allLayoutStructTypes.push_back(stTy);
}
}
}

// This is to make sure to reuse the layout types. Two identified structs have
// the same layout if
// 1. both are SOA or both are AOS; and
Expand All @@ -3448,7 +3426,8 @@ void LdStCombine::initLayoutStructType(Module* M)
StructType* LdStCombine::getOrCreateUniqueIdentifiedStructType(
ArrayRef<Type*> EltTys, bool IsSOA, bool IsPacked)
{
for (auto II : m_allLayoutStructTypes) {
auto& layoutStructTypes = m_CGC->getLayoutStructTypes();
for (auto II : layoutStructTypes) {
StructType* stTy = II;
if (IsPacked == stTy->isPacked() &&
IsSOA == isLayoutStructTypeSOA(stTy) &&
Expand All @@ -3460,7 +3439,7 @@ StructType* LdStCombine::getOrCreateUniqueIdentifiedStructType(
StructType* StTy = StructType::create(EltTys,
IsSOA ? getStructNameForSOALayout() : getStructNameForAOSLayout(),
IsPacked);
m_allLayoutStructTypes.push_back(StTy);
layoutStructTypes.push_back(StTy);
return StTy;
}

Expand Down
6 changes: 6 additions & 0 deletions IGC/Compiler/CodeGenPublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ namespace IGC
SafeIntrinsicIDCacheTy m_SafeIntrinsicIDCache;
/// metadata caching
UserAddrSpaceMD m_UserAddrSpaceMD;
// structType caching : for unique identified struct type
llvm::SmallVector<llvm::StructType*, 16> m_allLayoutStructTypes;
void AddRef();
void Release();
};
Expand Down Expand Up @@ -1101,6 +1103,10 @@ namespace IGC
IGC_ASSERT(llvmCtxWrapper);
return llvmCtxWrapper->m_UserAddrSpaceMD;
}
llvm::SmallVector<llvm::StructType*, 16>& getLayoutStructTypes() {
IGC_ASSERT(llvmCtxWrapper);
return llvmCtxWrapper->m_allLayoutStructTypes;
}

unsigned int GetSIMDInfoOffset(SIMDMode simd, ShaderDispatchMode mode)
{
Expand Down

0 comments on commit de5dc9e

Please sign in to comment.