Visitar URL original
T2-C7a: Devirtualize InlineBase — all 7/7 dynamic_cast eliminated · SonicField/cpython@f2a4444 · GitHub
Skip to content

Commit f2a4444

Browse files
committed
T2-C7a: Devirtualize InlineBase — all 7/7 dynamic_cast eliminated
Remove virtual from InlineBase::~InlineBase() and InlineBase::inlineDepth(). Neither is called through InlineBase* — all call sites use concrete types (BeginInlinedFunction* or EndInlinedFunction*). This eliminates the InlineBase vtable pointer from Begin/EndInlinedFunction, enabling conversion python#7 (gen_asm.cpp BeginInlinedFunction dynamic_cast → static_cast). With InlineBase non-polymorphic, static_cast from Instr* to BeginInlinedFunction* no longer involves secondary base adjustment. C struct updates: - Remove void *_vtable_inline from HirEndInlinedFunction - Remove void *_vtable_inline from HirBeginInlinedFunction All 7/7 dynamic_cast sites now converted to opcode predicates + static_cast.
1 parent 4956f22 commit f2a4444

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎Python/jit/codegen/gen_asm.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3653,7 +3653,7 @@ int NativeGenerator::calcInlineStackSize(const hir::Function* func) {
36533653
if (instr.opcode() != Opcode::kBeginInlinedFunction) {
36543654
continue;
36553655
}
3656-
auto bif = dynamic_cast<const BeginInlinedFunction*>(&instr);
3656+
auto bif = static_cast<const BeginInlinedFunction*>(&instr);
36573657
#if PY_VERSION_HEX >= 0x030C0000
36583658
int depth = frameHeaderSize(bif->code());
36593659
for (auto frame = bif->callerFrameState(); frame != nullptr;

‎Python/jit/hir/hir.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,8 +1572,9 @@ class INSTR_CLASS(
15721572

15731573
class InlineBase {
15741574
public:
1575-
virtual ~InlineBase() = default;
1576-
virtual int inlineDepth() const = 0;
1575+
~InlineBase() = default;
1576+
// Non-virtual: never called through InlineBase*. Concrete types
1577+
// provide their own implementation (T2-C7a devirtualization).
15771578
};
15781579

15791580
// Owns a FrameState that all inlined FrameState-owning instructions will point
@@ -1624,7 +1625,7 @@ class INSTR_CLASS(BeginInlinedFunction, (), Operands<0>), public InlineBase {
16241625
return reifier_;
16251626
}
16261627

1627-
int inlineDepth() const override {
1628+
int inlineDepth() const {
16281629
return caller_state_->inlineDepth() + 1;
16291630
}
16301631

@@ -1649,7 +1650,7 @@ class INSTR_CLASS(EndInlinedFunction, (), Operands<0>), public InlineBase {
16491650
return begin_;
16501651
}
16511652

1652-
int inlineDepth() const override {
1653+
int inlineDepth() const {
16531654
return inline_depth_;
16541655
}
16551656

‎Python/jit/hir/hir_instr_c.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ typedef struct { HIR_INSTR_FIELDS; int32_t cache_id; } HirLoadTypeMethodCacheEnt
132132

133133
/* ---- Multi-field (Instr base) ---- */
134134
typedef struct { HIR_INSTR_FIELDS; void *addr; HirType ret_type; } HirCallStatic;
135-
typedef struct { HIR_INSTR_FIELDS; void *_vtable_inline; void *begin; int32_t inline_depth; } HirEndInlinedFunction;
135+
typedef struct { HIR_INSTR_FIELDS; void *begin; int32_t inline_depth; } HirEndInlinedFunction;
136136
typedef struct { HIR_INSTR_FIELDS; int32_t line_no; int32_t _pad; void *parent; } HirUpdatePrevInstr;
137137
typedef struct { HIR_INSTR_FIELDS; uint32_t arg_idx; int32_t _pad; HirType type; } HirLoadArg;
138138

@@ -189,7 +189,7 @@ typedef struct { HIR_INSTR_FIELDS; char name_storage[32]; size_t offset; HirType
189189
typedef struct { HIR_INSTR_FIELDS; char basic_blocks_storage[24]; } HirPhi;
190190

191191
/* ---- Complex multi-inheritance + container types ---- */
192-
typedef struct { HIR_INSTR_FIELDS; void *_vtable_inline; void *func; void *reifier; void *caller_state_ptr; char fullname_storage[32]; } HirBeginInlinedFunction;
192+
typedef struct { HIR_INSTR_FIELDS; void *func; void *reifier; void *caller_state_ptr; char fullname_storage[32]; } HirBeginInlinedFunction;
193193

194194
/* ---- Opaque nested container (ProfiledTypes) ---- */
195195
typedef struct { HIR_INSTR_FIELDS; char types_storage[24]; } HirHintType;

0 commit comments

Comments
 (0)