Skip to content

Commit

Permalink
Defer DiaSession's symbol init (it is unused by WinPix (or anyone?)) (#…
Browse files Browse the repository at this point in the history
…6187)

The init of the dia symbol manager presents an unneccessary performance
hit for WinPix. It's quite simple to defer the init, so here we are.
(This dia implementation was originally added specifically for WinPix,
but was then superseded by a simpler API. It's entirely possible that
there are no other clients of the dia interface at all, but it has been
published, so we're probably bound to maintain it.)
(Note that there are other deferment opportunities here, but the larger
pending work is to disentangle the dia implementation from that of the
new "IDxcPix*" API that WinPix uses, which would obviate deferment
altogether, but that's way out of scope for me for now.)
  • Loading branch information
jeffnn authored Jan 23, 2024
1 parent 40853a5 commit 05b9413
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions lib/DxilDia/DxilDiaSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ void dxil_dia::Session::Init(std::shared_ptr<llvm::LLVMContext> context,
DXASSERT(m_rvaMap[It->second] == It->first,
"instruction mapped to wrong rva");
}
}

// Initialize symbols
try {
m_symsMgr.Init(this);
} catch (const hlsl::Exception &) {
m_symsMgr = dxil_dia::SymbolManager();
const dxil_dia::SymbolManager &dxil_dia::Session::SymMgr() {
if (!m_symsMgr) {
try {
m_symsMgr.reset(new dxil_dia::SymbolManager());
m_symsMgr->Init(this);
} catch (const hlsl::Exception &) {
m_symsMgr.reset(new dxil_dia::SymbolManager());
}
}
return *m_symsMgr;
}

HRESULT dxil_dia::Session::getSourceFileIdByName(llvm::StringRef fileName,
Expand Down Expand Up @@ -138,7 +143,7 @@ STDMETHODIMP dxil_dia::Session::get_globalScope(
*pRetVal = nullptr;

Symbol *ret;
IFR(m_symsMgr.GetGlobalScope(&ret));
IFR(SymMgr().GetGlobalScope(&ret));
*pRetVal = ret;
return S_OK;
}
Expand Down Expand Up @@ -378,7 +383,7 @@ STDMETHODIMP dxil_dia::Session::findInlineFramesByAddr(

HRESULT hr;
SymbolChildrenEnumerator *ChildrenEnum;
IFR(hr = m_symsMgr.DbgScopeOf(It->second, &ChildrenEnum));
IFR(hr = SymMgr().DbgScopeOf(It->second, &ChildrenEnum));

*ppResult = ChildrenEnum;
return hr;
Expand Down
4 changes: 2 additions & 2 deletions lib/DxilDia/DxilDiaSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Session : public IDiaSession, public IDxcPixDxilDebugInfoFactory {
hlsl::DxilModule &DxilModuleRef() { return *m_dxilModule.get(); }
llvm::Module &ModuleRef() { return *m_module.get(); }
llvm::DebugInfoFinder &InfoRef() { return *m_finder.get(); }
const SymbolManager &SymMgr() const { return m_symsMgr; }
const SymbolManager &SymMgr();
const RVAMap &InstructionsRef() const { return m_instructions; }
const std::vector<const llvm::Instruction *> &InstructionLinesRef() const {
return m_instructionLines;
Expand Down Expand Up @@ -499,7 +499,7 @@ class Session : public IDiaSession, public IDxcPixDxilDebugInfoFactory {
std::unordered_map<const llvm::Instruction *, RVA>
m_rvaMap; // Map instruction to its RVA.
LineToInfoMap m_lineToInfoMap;
SymbolManager m_symsMgr;
std::unique_ptr<SymbolManager> m_symsMgr;

private:
CComPtr<IDiaEnumTables> m_pEnumTables;
Expand Down

0 comments on commit 05b9413

Please sign in to comment.