From f7a72e5423ee0eda70762a3f87a45bb92fc84c97 Mon Sep 17 00:00:00 2001 From: kat Date: Sat, 2 Nov 2024 16:20:23 -0400 Subject: [SharedCache] Optimizations for symbol resolution workflow --- view/sharedcache/workflow/SharedCacheWorkflow.cpp | 56 +++++++++++++++-------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'view/sharedcache/workflow/SharedCacheWorkflow.cpp') diff --git a/view/sharedcache/workflow/SharedCacheWorkflow.cpp b/view/sharedcache/workflow/SharedCacheWorkflow.cpp index 4b4e464e..88353bf7 100644 --- a/view/sharedcache/workflow/SharedCacheWorkflow.cpp +++ b/view/sharedcache/workflow/SharedCacheWorkflow.cpp @@ -120,10 +120,6 @@ void SharedCacheWorkflow::FixupStubs(Ref ctx) const auto bv = func->GetView(); auto workflowState = GetGlobalWorkflowState(bv); - Ref cache = new SharedCacheAPI::SharedCache(bv); - - if (!cache) - return; auto funcStart = func->GetStart(); auto sectionExists = !bv->GetSectionsAt(funcStart).empty(); @@ -202,6 +198,14 @@ void SharedCacheWorkflow::FixupStubs(Ref ctx) auto def = mssa->GetSSAVarDefinition(dest.GetSourceSSAVariable()); auto defInstr = mssa->GetInstruction(def); auto targetOffset = defInstr.GetSourceExpr().GetSourceExpr().GetConstant(); + + if (bv->IsValidOffset(targetOffset)) + return; + + Ref cache = new SharedCacheAPI::SharedCache(bv); + + if (!cache) + return; if (!cache->GetImageNameForAddress(targetOffset).empty()) { cache->LoadImageContainingAddress(targetOffset); @@ -236,6 +240,14 @@ void SharedCacheWorkflow::FixupStubs(Ref ctx) std::unique_lock lock(workflowState->imageLoadMutex); auto dest = instr.GetDestExpr(); auto targetOffset = dest.GetConstant(); + if (bv->IsValidOffset(targetOffset)) + return; + + Ref cache = new SharedCacheAPI::SharedCache(bv); + + if (!cache) + return; + if (!cache->GetImageNameForAddress(targetOffset).empty()) { cache->LoadImageContainingAddress(targetOffset); @@ -338,24 +350,28 @@ void SharedCacheWorkflow::FixupStubs(Ref ctx) auto def = mssa->GetSSAVarDefinition(dest.GetSourceSSAVariable()); auto defInstr = mssa->GetInstruction(def); auto targetOffset = defInstr.GetSourceExpr().GetSourceExpr().GetConstant(); - auto sharedCache = SharedCacheAPI::SharedCache(bv); - if (!bv->IsValidOffset(targetOffset)) + + if (bv->IsValidOffset(targetOffset)) + return; + + Ref cache = new SharedCacheAPI::SharedCache(bv); + + if (!cache) + return; + + if (!cache->GetImageNameForAddress(targetOffset).empty()) { - if (!sharedCache.GetImageNameForAddress(targetOffset).empty()) - { - sharedCache.LoadImageContainingAddress(targetOffset); - } - else - { - sharedCache.LoadSectionAtAddress(targetOffset); - } - for (const auto& sectFunc : bv->GetAnalysisFunctionList()) + cache->LoadImageContainingAddress(targetOffset); + } + else + { + cache->LoadSectionAtAddress(targetOffset); + } + for (const auto §Func : bv->GetAnalysisFunctionList()) + { + if (section->GetStart() <= sectFunc->GetStart() && sectFunc->GetStart() < section->GetEnd()) { - if (section->GetStart() <= sectFunc->GetStart() - && sectFunc->GetStart() < section->GetEnd()) - { - func->Reanalyze(); - } + func->Reanalyze(); } } } -- cgit v1.3.1