Skip to content

Commit 32d3bc7

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Make MemoryView fields private
Summary: Cleaning up clang-tidy warnings about how this is being constructed, might as well make this a class. Reviewed By: yoney Differential Revision: D115776510 fbshipit-source-id: 3a06aa8c6a8f8a8b3d6cc1e79a0f4dc831f0b20a
1 parent e88614f commit 32d3bc7

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

cinderx/Jit/deopt.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ const char* deoptReasonName(DeoptReason reason) {
340340
JIT_ABORT("Invalid DeoptReason {}", static_cast<int>(reason));
341341
}
342342

343+
MemoryView::MemoryView(const uint64_t* regs) : regs_{regs} {}
344+
343345
BorrowedRef<> MemoryView::readBorrowed(const LiveValue& value) const {
344346
JIT_CHECK(
345347
value.value_kind == jit::hir::ValueKind::kObject,
@@ -364,13 +366,23 @@ Ref<> MemoryView::readOwned(const LiveValue& value) const {
364366
// Everything else is a primitive that has to be boxed into a new object. A
365367
// single LiveValue can back several frame-state slots, which all held one
366368
// object in the interpreter, so box it once and hand out references to that.
367-
Ref<>& boxed = boxed_primitives[&value];
369+
Ref<>& boxed = boxed_primitives_[&value];
368370
if (boxed == nullptr) {
369371
boxed = boxPrimitive(value.value_kind, raw);
370372
}
371373
return Ref<>::create(boxed.get());
372374
}
373375

376+
uint64_t MemoryView::readRaw(const LiveValue& value) const {
377+
codegen::PhyLocation loc = value.location;
378+
if (loc.isRegister()) {
379+
return regs_[loc.loc];
380+
}
381+
uint64_t frame_pointer = regs_[codegen::arch::reg_frame_pointer_loc.loc];
382+
// loc.loc is relative offset from RBP (i.e. negative as stack grows down)
383+
return *(reinterpret_cast<uint64_t*>(frame_pointer + loc.loc));
384+
}
385+
374386
Ref<> profileDeopt(const DeoptMetadata& meta, const MemoryView& mem) {
375387
BorrowedRef<PyCodeObject> code = meta.innermostFrame().code;
376388
BCOffset bc_off = meta.innermostFrame().cause_instr_idx;

cinderx/Jit/deopt.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,25 +222,20 @@ struct DeoptMetadata {
222222
// One instance should cover a whole deopt: reading a primitive live value has
223223
// to box it, and the cache below is what keeps every frame-state slot backed
224224
// by that value pointing at a single object.
225-
struct MemoryView {
226-
const uint64_t* regs;
227-
228-
// Objects materialized for primitive live values, keyed by the value they
229-
// came from. Holds a reference for as long as this view is alive.
230-
mutable UnorderedMap<const LiveValue*, Ref<>> boxed_primitives;
225+
class MemoryView {
226+
public:
227+
explicit MemoryView(const uint64_t* regs);
231228

232229
BorrowedRef<> readBorrowed(const LiveValue& value) const;
233230
Ref<> readOwned(const LiveValue& value) const;
231+
uint64_t readRaw(const LiveValue& value) const;
234232

235-
uint64_t readRaw(const LiveValue& value) const {
236-
codegen::PhyLocation loc = value.location;
237-
if (loc.isRegister()) {
238-
return regs[loc.loc];
239-
}
240-
uint64_t frame_pointer = regs[codegen::arch::reg_frame_pointer_loc.loc];
241-
// loc.loc is relative offset from RBP (i.e. negative as stack grows down)
242-
return *(reinterpret_cast<uint64_t*>(frame_pointer + loc.loc));
243-
}
233+
private:
234+
const uint64_t* regs_;
235+
236+
// Objects materialized for primitive live values, keyed by the value they
237+
// came from. Holds a reference for as long as this view is alive.
238+
mutable UnorderedMap<const LiveValue*, Ref<>> boxed_primitives_;
244239
};
245240

246241
// Update `frame` so that execution can resume in the interpreter.

0 commit comments

Comments
 (0)