Skip to content

[2/2] [MooreToCore] Lower vtable method loads and vptr init#10130

Draft
Scheremo wants to merge 2 commits intollvm:mainfrom
Scheremo:pr-class-vtable-4
Draft

[2/2] [MooreToCore] Lower vtable method loads and vptr init#10130
Scheremo wants to merge 2 commits intollvm:mainfrom
Scheremo:pr-class-vtable-4

Conversation

@Scheremo
Copy link
Copy Markdown
Contributor

@Scheremo Scheremo commented Apr 5, 2026

Extend class allocation and dispatch lowering to use the concrete vtable
ABI introduced in earlier steps.

This factors out vtable lookup, initializes the object header's vptr when
allocating classes that have a symbolic vtable, and lowers
moore.vtable.load_method into header access, vtable load, slot GEP, and
function-pointer load. Upcasted dispatch remains pointer-preserving and
reuses the concrete object's vptr.

Refine the header GEP sequence to first step through the object header and
then index within the header struct, matching the canonical layout explicitly.

Update MooreToCore tests to check vptr initialization during class.new,
dynamic method slot lookup, indirect dispatch, and dispatch through an
upcasted receiver.

Also fixes a previous issue that would try to call a func.func malloc;
new now uses llvm.func malloc to avoid later linkage issues.

@Scheremo Scheremo force-pushed the pr-class-vtable-4 branch 4 times, most recently from 73588f9 to e127cd8 Compare April 5, 2026 18:33
@fabianschuiki
Copy link
Copy Markdown
Contributor

Results of circt-tests run for e127cd8 compared to results for 1696571:

sv-tests

Changes in emitted diagnostics:

  • -6 total change
  • -7 error: failed to legalize operation 'moore.vtable.load_method'
  • -4 error: failed to legalize operation 'moore.vtable'
  • +2 error: 'llvm.return' op operand #0 must be LLVM dialect-compatible type, but got '!sim.queue<i32, 0>'
  • -1 error: failed to legalize operation 'func.call'
  • +1 error: 'llvm.call' op 'malloc' does not reference a valid LLVM function or IFunc
  • +1 error: 'llvm.call' op result #0 must be LLVM dialect-compatible type, but got '!sim.queue<i32, 0>'
  • +1 error: Could not resolve vtable for @"class_tb::helloworld"
  • +1 error: failed to legalize operation 'moore.fmt.string'

Materialize Moore vtables as LLVM globals and convert referenced method
bodies to LLVM-addressable functions on demand while keeping `func.func`
functions for any methods not involved in virtual dispatch.

This adds cached vtable metadata, flattens nested `moore.vtable`
hierarchies into a concrete slot order, and emits one LLVM global per
class vtable with real function-pointer entries. When a slot target is
still a `func.func`, convert it to `llvm.func` before taking its address
so the vtable initializer contains valid LLVM function pointers.

[MooreToCore] Narrow vtable lowering integration
@Scheremo Scheremo changed the title DRAFT: [4/4] [MooreToCore] Lower vtable method loads and vptr init [2/3] [MooreToCore] Lower vtable method loads and vptr init Apr 9, 2026
@Scheremo Scheremo marked this pull request as ready for review April 9, 2026 07:25
@Scheremo Scheremo force-pushed the pr-class-vtable-4 branch 3 times, most recently from 16df605 to b2b80b7 Compare April 9, 2026 07:40
@Scheremo Scheremo changed the title [2/3] [MooreToCore] Lower vtable method loads and vptr init [2/2] [MooreToCore] Lower vtable method loads and vptr init Apr 9, 2026
@Scheremo Scheremo force-pushed the pr-class-vtable-4 branch from b2b80b7 to 40f69ac Compare April 9, 2026 07:52
Extend class allocation and dispatch lowering to use the concrete vtable
ABI introduced in earlier steps.

This factors out vtable lookup, initializes the object header's vptr when
allocating classes that have a symbolic vtable, and lowers
moore.vtable.load_method into header access, vtable load, slot GEP, and
function-pointer load. Upcasted dispatch remains pointer-preserving and
reuses the concrete object's vptr.

Refine the header GEP sequence to first step through the object header and
then index within the header struct, matching the canonical layout explicitly.

Update MooreToCore tests to check vptr initialization during class.new,
dynamic method slot lookup, indirect dispatch, and dispatch through an
upcasted receiver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants