Skip to content

Commit 4d79fcf

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Merge JIT's Context and Runtime classes into single Context class
Summary: Coded up via Claude... We currently have a JIT "Context" and a JIT "Runtime" - they both claim that they store data associated with the JIT although the Runtime claims it's "metadata". Really there's an assortment of data smeared between the two - e.g. the Runtime stores inline caches which are used by the JITed code. More importantly this distinction makes it harder to root other data structures in our shared state. We can end up needing to hold onto either the Runtime or the Context to do things or both. We could just hold onto the Module state but that is in some places because it otherwise has so many dependencies. Reviewed By: jbower-fb Differential Revision: D91935928 fbshipit-source-id: 219d14d1a054611f6c7ea25569c88deef3acd92e
1 parent dcfba7b commit 4d79fcf

23 files changed

Lines changed: 772 additions & 834 deletions

cinderx/Jit/codegen/environ.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "cinderx/Jit/codegen/annotations.h"
66
#include "cinderx/Jit/codegen/arch.h"
77
#include "cinderx/Jit/containers.h"
8+
#include "cinderx/Jit/context.h"
89
#include "cinderx/Jit/debug_info.h"
9-
#include "cinderx/Jit/runtime.h"
1010

1111
#include <asmjit/asmjit.h>
1212

@@ -82,7 +82,7 @@ struct Environ {
8282
function_typed_args;
8383

8484
// Global runtime data.
85-
jit::Runtime* rt{nullptr};
85+
jit::Context* ctx{nullptr};
8686

8787
// Runtime data for this function.
8888
jit::CodeRuntime* code_rt{nullptr};

cinderx/Jit/codegen/frame_asm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "cinderx/Jit/codegen/register_preserver.h"
88
#include "cinderx/Jit/hir/function.h"
99
#include "cinderx/Jit/hir/hir.h"
10-
#include "cinderx/Jit/runtime.h"
1110

1211
#include <asmjit/asmjit.h>
1312

cinderx/Jit/codegen/gen_asm.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "cinderx/Jit/codegen/gen_asm_utils.h"
2525
#include "cinderx/Jit/compiled_function.h"
2626
#include "cinderx/Jit/config.h"
27+
#include "cinderx/Jit/context.h"
2728
#include "cinderx/Jit/frame.h"
2829
#include "cinderx/Jit/frame_header.h"
2930
#include "cinderx/Jit/generators_rt.h"
@@ -40,7 +41,6 @@
4041
#include "cinderx/Jit/lir/regalloc.h"
4142
#include "cinderx/Jit/lir/verify.h"
4243
#include "cinderx/Jit/perf_jitdump.h"
43-
#include "cinderx/Jit/runtime.h"
4444
#include "cinderx/UpstreamBorrow/borrowed.h"
4545

4646
#include <fmt/format.h>
@@ -213,8 +213,8 @@ CiPyFrameObjType* prepareForDeopt(
213213
// Clear our references now that we've transferred them to the frame
214214
MemoryView mem{regs};
215215
Ref<> deopt_obj = profileDeopt(deopt_meta, mem);
216-
auto runtime = Runtime::get();
217-
runtime->recordDeopt(code_runtime, deopt_idx, deopt_obj);
216+
auto ctx = getContext();
217+
ctx->recordDeopt(code_runtime, deopt_idx, deopt_obj);
218218
releaseRefs(deopt_meta, mem);
219219
#if PY_VERSION_HEX >= 0x030C0000
220220
if (_PyFrame_GetCode(frame)->co_flags & kCoFlagsAnyGenerator) {
@@ -228,7 +228,7 @@ CiPyFrameObjType* prepareForDeopt(
228228
auto reason = deopt_meta.reason;
229229
switch (reason) {
230230
case DeoptReason::kGuardFailure: {
231-
runtime->guardFailed(deopt_meta);
231+
ctx->guardFailed(deopt_meta);
232232
break;
233233
}
234234
case DeoptReason::kRaise:
@@ -845,8 +845,8 @@ void* NativeGenerator::getVectorcallEntry() {
845845

846846
auto func = GetFunction();
847847

848-
env_.rt = Runtime::get();
849-
env_.code_rt = env_.rt->allocateCodeRuntime(
848+
env_.ctx = getContext();
849+
env_.code_rt = env_.ctx->allocateCodeRuntime(
850850
func->code.get(), func->builtins.get(), func->globals.get());
851851
#if defined(ENABLE_LIGHTWEIGHT_FRAMES) && PY_VERSION_HEX >= 0x030E0000
852852
env_.code_rt->setReifier(func->reifier);
@@ -1546,7 +1546,7 @@ void NativeGenerator::linkDeoptPatchers(const asmjit::CodeHolder& code) {
15461546

15471547
// Register patcher with the runtime if it is type-based.
15481548
if (auto typed_patcher = dynamic_cast<TypeDeoptPatcher*>(udp.patcher)) {
1549-
env_.rt->watchType(typed_patcher->type(), typed_patcher);
1549+
env_.ctx->watchType(typed_patcher->type(), typed_patcher);
15501550
}
15511551
}
15521552

0 commit comments

Comments
 (0)