From 3b37eb4b3a437227a75dae76176e609e96f8e0f9 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Fri, 12 Sep 2025 18:15:42 -0700 Subject: [PATCH] consolidate information associated with function bodies --- src/script_opt/CPP/DeclFunc.cc | 4 +--- src/script_opt/CPP/Driver.cc | 8 +++++--- src/script_opt/CPP/GenFunc.cc | 6 +++--- src/script_opt/CPP/GenFunc.h | 15 +++++++-------- src/script_opt/CPP/Inits.cc | 6 +++--- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/script_opt/CPP/DeclFunc.cc b/src/script_opt/CPP/DeclFunc.cc index d2d8ec7516..21e1ba7ef9 100644 --- a/src/script_opt/CPP/DeclFunc.cc +++ b/src/script_opt/CPP/DeclFunc.cc @@ -103,9 +103,7 @@ void CPPCompile::CreateFunction(const FuncTypePtr& ft, const ProfileFunc* pf, co compiled_funcs.emplace(fname); } - body_hashes[fname] = pf->HashVal(); - body_priorities[fname] = priority; - body_locs[fname] = body->GetLocationInfo(); + body_info[fname] = {.hash = pf->HashVal(), .priority = priority, .loc = body->GetLocationInfo()}; body_names.emplace(body.get(), fname); } diff --git a/src/script_opt/CPP/Driver.cc b/src/script_opt/CPP/Driver.cc index 66ad6b7fa7..727daba30f 100644 --- a/src/script_opt/CPP/Driver.cc +++ b/src/script_opt/CPP/Driver.cc @@ -378,9 +378,11 @@ void CPPCompile::RegisterCompiledBody(const string& f) { ASSERT(fi != func_index.end()); auto type_signature = casting_index[fi->second]; - auto h = body_hashes[f]; - auto p = body_priorities[f]; - auto loc = body_locs[f]; + const auto& bi = body_info[f]; + + auto h = bi.hash; + auto p = bi.priority; + auto loc = bi.loc; auto body_info = Fmt(p) + ", " + Fmt(h) + ", \"" + loc->FileName() + " (C++)\", " + Fmt(loc->FirstLine()); Emit("\tCPP_RegisterBody(\"%s\", (void*) %s, %s, %s, std::vector(%s)),", f, f, Fmt(type_signature), diff --git a/src/script_opt/CPP/GenFunc.cc b/src/script_opt/CPP/GenFunc.cc index d171dc5fd4..88d5bfc435 100644 --- a/src/script_opt/CPP/GenFunc.cc +++ b/src/script_opt/CPP/GenFunc.cc @@ -224,10 +224,10 @@ p_hash_type CPPCompile::BodyHash(const Stmt* body) { ASSERT(bn != body_names.end()); auto& body_name = bn->second; - auto bh = body_hashes.find(body_name); - ASSERT(bh != body_hashes.end()); + auto bi = body_info.find(body_name); + ASSERT(bi != body_info.end()); - return bh->second; + return bi->second.hash; } string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e) { diff --git a/src/script_opt/CPP/GenFunc.h b/src/script_opt/CPP/GenFunc.h index 13427b9689..35345bab38 100644 --- a/src/script_opt/CPP/GenFunc.h +++ b/src/script_opt/CPP/GenFunc.h @@ -51,15 +51,14 @@ std::unordered_map compiled_simple_funcs; // Maps function bodies to the names we use for them. std::unordered_map body_names; -// Maps function names to hashes of bodies. -std::unordered_map body_hashes; +struct BodyInfo { + p_hash_type hash; + int priority; + const Location* loc; // for better-than-nothing error reporting +}; -// Maps function names to priorities, for hooks & event handlers. -std::unordered_map body_priorities; - -// Maps function names to script locations, for better-than-nothing error -// reporting. -std::unordered_map body_locs; +// Maps function names to their body info. +std::unordered_map body_info; // Maps function names to events relevant to them. std::unordered_map> body_events; diff --git a/src/script_opt/CPP/Inits.cc b/src/script_opt/CPP/Inits.cc index 72fafef9a4..20c0b57a89 100644 --- a/src/script_opt/CPP/Inits.cc +++ b/src/script_opt/CPP/Inits.cc @@ -285,9 +285,9 @@ void CPPCompile::GenStandaloneActivation() { // We didn't wind up compiling it. continue; - auto bh = body_hashes.find(bname); - ASSERT(bh != body_hashes.end()); - func_bodies[f].push_back(bh->second); + auto bi = body_info.find(bname); + ASSERT(bi != body_info.end()); + func_bodies[f].push_back(bi->second.hash); } for ( auto& fb : func_bodies ) {