From de5dc9e19a2ccbc7472fd6d6fe0be1b0990e47d7 Mon Sep 17 00:00:00 2001 From: "Gu, Junjie" Date: Sat, 14 Oct 2023 01:04:30 +0000 Subject: [PATCH] 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. --- IGC/Compiler/CISACodeGen/MemOpt.cpp | 27 +++------------------------ IGC/Compiler/CodeGenPublic.h | 6 ++++++ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/IGC/Compiler/CISACodeGen/MemOpt.cpp b/IGC/Compiler/CISACodeGen/MemOpt.cpp index b135b937e2d1..a05d75307d7c 100644 --- a/IGC/Compiler/CISACodeGen/MemOpt.cpp +++ b/IGC/Compiler/CISACodeGen/MemOpt.cpp @@ -2561,8 +2561,6 @@ namespace { bool getAddressDiffIfConstant(Instruction* I0, Instruction* I1, int64_t& ConstBO); // Create unique identified struct type - SmallVector m_allLayoutStructTypes; - void initLayoutStructType(Module* M); StructType* getOrCreateUniqueIdentifiedStructType( ArrayRef EltTys, bool IsSOA, bool IsPacked = true); @@ -2576,7 +2574,6 @@ namespace { m_visited.clear(); m_instOrder.clear(); m_bundles.clear(); - m_allLayoutStructTypes.clear(); } }; } @@ -2799,8 +2796,6 @@ bool LdStCombine::runOnFunction(Function& F) } m_F = &F; - initLayoutStructType(m_F->getParent()); - // Initialize symbolic evaluation m_symEval.setDataLayout(m_DL); @@ -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 @@ -3448,7 +3426,8 @@ void LdStCombine::initLayoutStructType(Module* M) StructType* LdStCombine::getOrCreateUniqueIdentifiedStructType( ArrayRef 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) && @@ -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; } diff --git a/IGC/Compiler/CodeGenPublic.h b/IGC/Compiler/CodeGenPublic.h index bd9a3eaba367..0dd6acf962fe 100644 --- a/IGC/Compiler/CodeGenPublic.h +++ b/IGC/Compiler/CodeGenPublic.h @@ -849,6 +849,8 @@ namespace IGC SafeIntrinsicIDCacheTy m_SafeIntrinsicIDCache; /// metadata caching UserAddrSpaceMD m_UserAddrSpaceMD; + // structType caching : for unique identified struct type + llvm::SmallVector m_allLayoutStructTypes; void AddRef(); void Release(); }; @@ -1101,6 +1103,10 @@ namespace IGC IGC_ASSERT(llvmCtxWrapper); return llvmCtxWrapper->m_UserAddrSpaceMD; } + llvm::SmallVector& getLayoutStructTypes() { + IGC_ASSERT(llvmCtxWrapper); + return llvmCtxWrapper->m_allLayoutStructTypes; + } unsigned int GetSIMDInfoOffset(SIMDMode simd, ShaderDispatchMode mode) {