Skip to content

Commit

Permalink
Merge ProfileData into ProfileRuntime
Browse files Browse the repository at this point in the history
Summary:
Collapsing the two singletons into one.  All profiling bookkeeping is now held
within the ProfileRuntime instance, with the exception of the LiveTypeMap.  Our
tests depend upon this structure having a global lifetime.

Notable behavior changes:

* All overloads of `serialize()` and `deserialize()` will now print the number
  of bytes, code objects, and types read/written.

* `RuntimeTest` no longer tears down the fixture after running and collecting a
  profile.  Doing so is a bit of a lie, we reset the JIT, but we can't actually
  reset the live types map because then we wouldn't be able to use the profile
  we saved (the string types don't have a mapping to anything).  So it's more
  natural to make the fixture run the code, generate profiling info, and then
  prepare to generate HIR without resetting the JIT metadata.

Reviewed By: swtaarrs

Differential Revision: D47607471

fbshipit-source-id: e2da98ba792bf0ae2713667a71d7be871a010ebd
  • Loading branch information
Alex Malyshev authored and facebook-github-bot committed Aug 4, 2023
1 parent d498b39 commit 9c814e1
Show file tree
Hide file tree
Showing 13 changed files with 434 additions and 547 deletions.
1 change: 0 additions & 1 deletion Cinder/module/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"Jit/live_type_map.cpp",
"Jit/log.cpp",
"Jit/perf_jitdump.cpp",
"Jit/profile_data.cpp",
"Jit/profile_runtime.cpp",
"Jit/pyjit.cpp",
"Jit/runtime.cpp",
Expand Down
6 changes: 4 additions & 2 deletions Jit/hir/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ BasicBlock* HIRBuilder::buildHIRImpl(
void HIRBuilder::emitProfiledTypes(
TranslationContext& tc,
const ProfileRuntime& profile_runtime,
const CodeKey& code_key,
const BytecodeInstruction& bc_instr) {
if (bc_instr.opcode() == CALL_METHOD) {
// TODO(T107300350): Ignore profiling data for CALL_METHOD because we lie
Expand All @@ -648,7 +649,7 @@ void HIRBuilder::emitProfiledTypes(
}

std::vector<Type> types =
profile_runtime.getProfiledTypes(tc.frame.code, bc_instr.offset());
profile_runtime.getProfiledTypes(code_key, bc_instr.offset());

if (types.empty() || types.size() > tc.frame.stack.size()) {
// The types are either absent or invalid (e.g., from a different version
Expand Down Expand Up @@ -765,6 +766,7 @@ void HIRBuilder::translate(
std::unordered_set<BasicBlock*> loop_headers;

auto const& profile_runtime = Runtime::get()->profileRuntime();
auto code_key = profile_runtime.codeKey(tc.frame.code);

while (!queue.empty()) {
auto tc = std::move(queue.front());
Expand All @@ -791,7 +793,7 @@ void HIRBuilder::translate(
BytecodeInstruction bc_instr = *bc_it;
tc.setCurrentInstr(bc_instr);

emitProfiledTypes(tc, profile_runtime, bc_instr);
emitProfiledTypes(tc, profile_runtime, code_key, bc_instr);

// Translate instruction
switch (bc_instr.opcode()) {
Expand Down
1 change: 1 addition & 0 deletions Jit/hir/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class HIRBuilder {
void emitProfiledTypes(
TranslationContext& tc,
const ProfileRuntime& profile_runtime,
const CodeKey& codeKey,
const BytecodeInstruction& bc_instr);

void emitBinaryOp(
Expand Down
Loading

0 comments on commit 9c814e1

Please sign in to comment.