From cb4c761a819e1ddbc0216f08a839818385c6819e Mon Sep 17 00:00:00 2001 From: Jan Oravec Date: Wed, 9 Jun 2021 13:48:48 -0700 Subject: [PATCH] ProfTransRec: use SrcKey instead of Offset Summary: Use SrcKey, which will be able to represent FuncEntry position. Reviewed By: ricklavoie Differential Revision: D28985409 fbshipit-source-id: 5d973252538214c8f6e6ad60dfb7655aac03b252 --- hphp/runtime/vm/jit/inlining-decider.cpp | 3 ++- hphp/runtime/vm/jit/prof-data-serialize.cpp | 12 ++++++------ hphp/runtime/vm/jit/prof-data.cpp | 14 +++++++------- hphp/runtime/vm/jit/prof-data.h | 26 ++++---------------------- hphp/runtime/vm/jit/region-hot-trace.cpp | 8 ++++---- hphp/runtime/vm/jit/regionize-func.cpp | 6 +++--- hphp/runtime/vm/jit/trans-cfg.cpp | 4 ++-- 7 files changed, 28 insertions(+), 45 deletions(-) diff --git a/hphp/runtime/vm/jit/inlining-decider.cpp b/hphp/runtime/vm/jit/inlining-decider.cpp index 30f138536e3..5fe83f372a5 100644 --- a/hphp/runtime/vm/jit/inlining-decider.cpp +++ b/hphp/runtime/vm/jit/inlining-decider.cpp @@ -642,11 +642,12 @@ TransIDSet findTransIDsForCallee(const ProfData* profData, const Func* callee, auto const idvec = profData->funcProfTransIDs(callee->getFuncId()); auto const offset = callee->getEntryForNumArgs(argTypes.size()); + auto const sk = SrcKey { callee, offset, ResumeMode::None }; TransIDSet ret; FTRACE(2, "findTransIDForCallee: offset={}\n", offset); for (auto const id : idvec) { auto const rec = profData->transRec(id); - if (rec->startBcOff() != offset) continue; + if (rec->srcKey() != sk) continue; auto const region = rec->region(); auto const isvalid = [&] () { diff --git a/hphp/runtime/vm/jit/prof-data-serialize.cpp b/hphp/runtime/vm/jit/prof-data-serialize.cpp index d8815920849..b0893809dee 100644 --- a/hphp/runtime/vm/jit/prof-data-serialize.cpp +++ b/hphp/runtime/vm/jit/prof-data-serialize.cpp @@ -375,7 +375,7 @@ void write_prof_trans_rec(ProfDataSerializer& ser, write_raw(ser, ptr->kind()); write_srckey(ser, ptr->srcKey()); if (ptr->kind() == TransKind::Profile) { - write_raw(ser, ptr->lastBcOff()); + write_raw(ser, ptr->lastSrcKey()); write_region_desc(ser, ptr->region().get()); write_raw(ser, ptr->asmSize()); } else { @@ -403,10 +403,10 @@ std::unique_ptr read_prof_trans_rec(ProfDataDeserializer& ser) { if (kind == TransKind{}) return nullptr; auto const sk = read_srckey(ser); if (kind == TransKind::Profile) { - auto const lastBcOff = read_raw(ser); + auto const lastSk = read_srckey(ser); auto const region = read_region_desc(ser); auto const asmSize = read_raw(ser); - return std::make_unique(lastBcOff, sk, region, asmSize); + return std::make_unique(lastSk, sk, region, asmSize); } auto ret = std::make_unique(sk, read_raw(ser), 0); @@ -703,13 +703,13 @@ void maybe_output_prof_trans_rec_trace( } } folly::dynamic profTransRecProfile = folly::dynamic::object; - profTransRecProfile["end_bytecode_offset"] = profTransRec->lastBcOff(); - profTransRecProfile["end_line_number"] = func->getLineNumber(profTransRec->lastBcOff()); + profTransRecProfile["end_bytecode_offset"] = profTransRec->lastSrcKey().printableOffset(); + profTransRecProfile["end_line_number"] = profTransRec->lastSrcKey().lineNumber(); profTransRecProfile["file_path"] = filePath; profTransRecProfile["function_name"] = sk.func()->fullName()->data(); profTransRecProfile["profile"] = folly::dynamic::object("profileType", "ProfTransRec"); profTransRecProfile["region"] = folly::dynamic::object("blocks", blocks); - profTransRecProfile["start_bytecode_offset"] = profTransRec->startBcOff(); + profTransRecProfile["start_bytecode_offset"] = profTransRec->srcKey().printableOffset(); profTransRecProfile["start_line_number"] = profTransRec->region()->start().lineNumber(); profTransRecProfile["translation_weight"] = translationWeight; HPHP::Trace::traceRelease("json:%s\n", folly::toJson(profTransRecProfile).c_str()); diff --git a/hphp/runtime/vm/jit/prof-data.cpp b/hphp/runtime/vm/jit/prof-data.cpp index 5f6e04cf672..e3df26901cc 100644 --- a/hphp/runtime/vm/jit/prof-data.cpp +++ b/hphp/runtime/vm/jit/prof-data.cpp @@ -35,22 +35,22 @@ TRACE_SET_MOD(pgo); //////////////////////////////////////////////////////////////////////////////// -ProfTransRec::ProfTransRec(Offset lastBcOff, SrcKey sk, RegionDescPtr region, +ProfTransRec::ProfTransRec(SrcKey lastSk, SrcKey sk, RegionDescPtr region, uint32_t asmSize) : m_kind(TransKind::Profile) - , m_lastBcOff(lastBcOff) + , m_asmSize(asmSize) + , m_lastSk(lastSk) , m_sk(sk) - , m_region(region) - , m_asmSize(asmSize){ + , m_region(region) { assertx(region != nullptr && !region->empty() && region->start() == sk); } ProfTransRec::ProfTransRec(SrcKey sk, int nArgs, uint32_t asmSize) : m_kind(TransKind::ProfPrologue) + , m_asmSize(asmSize) , m_prologueArgs(nArgs) , m_sk(sk) , m_callers{} - , m_asmSize(asmSize) { m_callers = std::make_unique(); } @@ -121,7 +121,7 @@ void ProfData::addTransProfile(TransID transID, const RegionDescPtr& region, const PostConditions& pconds, uint32_t asmSize) { - auto const lastBcOff = region->lastSrcKey().offset(); + auto const lastSk = region->lastSrcKey(); assertx(region); DEBUG_ONLY auto const nBlocks = region->blocks().size(); @@ -148,7 +148,7 @@ void ProfData::addTransProfile(TransID transID, { folly::SharedMutex::WriteHolder lock{m_transLock}; - m_transRecs[transID].reset(new ProfTransRec(lastBcOff, startSk, region, + m_transRecs[transID].reset(new ProfTransRec(lastSk, startSk, region, asmSize)); } diff --git a/hphp/runtime/vm/jit/prof-data.h b/hphp/runtime/vm/jit/prof-data.h index 1b2d24ec568..b17b7c26415 100644 --- a/hphp/runtime/vm/jit/prof-data.h +++ b/hphp/runtime/vm/jit/prof-data.h @@ -86,7 +86,7 @@ struct ProfTransRec { * Construct a ProfTransRec attached to a RegionDescPtr (region must be * non-null), for a profiling translation. */ - ProfTransRec(Offset lastBcOff, SrcKey sk, RegionDescPtr region, + ProfTransRec(SrcKey lastSk, SrcKey sk, RegionDescPtr region, uint32_t asmSize); /* @@ -112,31 +112,13 @@ struct ProfTransRec { } /* - * First BC offset in this translation. - */ - Offset startBcOff() const { - assertx(m_kind == TransKind::Profile); - return m_region->start().offset(); - } - - /* - * Last BC offset in this translation. - * - * Precondition: kind() == TransKind::Profile - */ - Offset lastBcOff() const { - assertx(m_kind == TransKind::Profile); - return m_lastBcOff; - } - - /* * SrcKey for last offset in translation. * * Precondition: kind() == TransKind::Profile */ SrcKey lastSrcKey() const { assertx(m_kind == TransKind::Profile); - return SrcKey{m_sk, m_lastBcOff}; + return m_lastSk; } /* @@ -236,8 +218,9 @@ private: } TransKind m_kind; + uint32_t m_asmSize; // size of the machine code union { - Offset m_lastBcOff; // offset of the last bytecode instr + SrcKey m_lastSk; // SrcKey of the last bytecode instr // for non-prologue translations int m_prologueArgs; // for prologues }; @@ -246,7 +229,6 @@ private: RegionDescPtr m_region; // for TransProfile translations CallerRecPtr m_callers; // for TransProfPrologue translations }; - uint32_t m_asmSize; // size of the machine code }; //////////////////////////////////////////////////////////////////////////////// diff --git a/hphp/runtime/vm/jit/region-hot-trace.cpp b/hphp/runtime/vm/jit/region-hot-trace.cpp index c9bcfacd4e5..ec257904c01 100644 --- a/hphp/runtime/vm/jit/region-hot-trace.cpp +++ b/hphp/runtime/vm/jit/region-hot-trace.cpp @@ -99,11 +99,11 @@ RegionDescPtr selectHotTrace(HotTransContext& ctx) { // large regions containing the function body (starting at various // DV funclets). if (prevId != kInvalidTransID) { - auto const bcOffset = rec->startBcOff(); - if (0 == bcOffset) { + auto const sk = rec->srcKey(); + if (sk.offset() == 0) { FTRACE(2, "selectHotTrace: breaking region because reached the main " - "function body entry at Translation {} (BC offset {})\n", - tid, bcOffset); + "function body entry at Translation {} (BC offset 0)\n", + tid); break; } } diff --git a/hphp/runtime/vm/jit/regionize-func.cpp b/hphp/runtime/vm/jit/regionize-func.cpp index 260c6536627..a8c75fb3817 100644 --- a/hphp/runtime/vm/jit/regionize-func.cpp +++ b/hphp/runtime/vm/jit/regionize-func.cpp @@ -312,9 +312,9 @@ RegionVec regionizeFunc(const Func* func, std::string& transCFGAnnot) { [&](TransID tid1, TransID tid2) -> bool { if (regionMode == PGORegionMode::WholeCFG || regionMode == PGORegionMode::HotCFG) { - auto bcOff1 = profData->transRec(tid1)->startBcOff(); - auto bcOff2 = profData->transRec(tid2)->startBcOff(); - if (bcOff1 != bcOff2) return bcOff1 < bcOff2; + auto sk1 = profData->transRec(tid1)->srcKey(); + auto sk2 = profData->transRec(tid2)->srcKey(); + if (sk1 != sk2) return sk1.offset() < sk2.offset(); } if (cfg.weight(tid1) != cfg.weight(tid2)) { return cfg.weight(tid1) > cfg.weight(tid2); diff --git a/hphp/runtime/vm/jit/trans-cfg.cpp b/hphp/runtime/vm/jit/trans-cfg.cpp index 125e385a47e..35e9a2e760a 100644 --- a/hphp/runtime/vm/jit/trans-cfg.cpp +++ b/hphp/runtime/vm/jit/trans-cfg.cpp @@ -239,8 +239,8 @@ void TransCFG::print(std::ostream& out, FuncId funcId, auto const w = weight(tid); uint32_t coldness = 255 - (255 * w / maxWeight); auto const rec = profData->transRec(tid); - auto const bcStart = rec->startBcOff(); - auto const bcStop = rec->lastBcOff(); + auto const bcStart = rec->srcKey().printableOffset(); + auto const bcStop = rec->lastSrcKey().printableOffset(); auto const shape = "box"; out << folly::sformat( "t{} [shape={},label=\"T: {}\\np: {}\\n" -- 2.11.4.GIT