Skip to content

Comments

Expose AOT compilation in C API.#3848

Open
meheff wants to merge 10 commits intogoogle:mainfrom
xlsynth:meheff/2026-02-03-aot
Open

Expose AOT compilation in C API.#3848
meheff wants to merge 10 commits intogoogle:mainfrom
xlsynth:meheff/2026-02-03-aot

Conversation

@meheff
Copy link
Collaborator

@meheff meheff commented Feb 14, 2026

Add a function for compiling and generating aot metadata, and a separate function for running the code from the generated artifacts. Use ORC JIT for loading the object code.

meheff added a commit to xlsynth/xlsynth that referenced this pull request Feb 14, 2026
meheff added a commit to xlsynth/xlsynth that referenced this pull request Feb 15, 2026
@meheff meheff force-pushed the meheff/2026-02-03-aot branch 2 times, most recently from c13114e to f2c072f Compare February 16, 2026 21:12
meheff added a commit to xlsynth/xlsynth that referenced this pull request Feb 17, 2026
meheff added a commit to xlsynth/xlsynth that referenced this pull request Feb 17, 2026
meheff added a commit to xlsynth/xlsynth that referenced this pull request Feb 17, 2026
Copy link
Contributor

@allight allight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any serious issues with this but looking at the xlsynth-crate branch I wonder if it might be simpler to just have fork-exec the aot_compiler_main and use it that way. This is a lot of code to cram into xls-c-api.

I also wonder whether it might be easier to give the aot stuff the ability to run lld (through the c++ library) and then a lot of this gets a bunch simpler since you can have your stuff just dlopen and dlsym the library.

@meheff meheff force-pushed the meheff/2026-02-03-aot branch from 885ba57 to cf697da Compare February 19, 2026 22:43
@meheff
Copy link
Collaborator Author

meheff commented Feb 19, 2026

Thanks for the review, Alex. I simplified things quite a bit which I think resolves your comments:

  • Removed xls_aot_run_function from the C API. This took object code and ran it with irvalues. This was more for testing than for production purposes and isn't really necessary.
  • Removed the added LoadObjectCode method from OrcJit. The test now just call llvm directly to load the object code.

Regarding fork-exec'ing aot_compiler_main, this would require carrying the aot_compiler_main binary along with the library. The proto generation code is already shared with aot_compiler_main, and the object code generation is just a single function call. The rest of the code in xls_aot_compile_function is just the verbose fluff needed to do things C style (manual allocation/free).

@meheff meheff force-pushed the meheff/2026-02-03-aot branch from 0b42825 to c5f277c Compare February 20, 2026 00:36
meheff added a commit to xlsynth/xlsynth that referenced this pull request Feb 20, 2026
@meheff meheff requested a review from allight February 20, 2026 03:34
Copy link
Contributor

@allight allight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change and LGTM.

I would like to remind you too that though we won't go around changing it for no reason the abi of our generated entrypoints shouldn't really be considered stable. We may want to change it dramatically for any number of reasons. Practically the only thing likely to be long term (relatively) stable are the external interfaces our wrapper rules create. For something more long term stable I'd really suggest having an api that you give the entrypoint pointer and metadata and it returns a handle that you can request to execute using some defined 'xls::Value' mirror in the c api. For now though this is fine.

@meheff meheff force-pushed the meheff/2026-02-03-aot branch from c5f277c to e5c7a63 Compare February 23, 2026 21:57
@meheff
Copy link
Collaborator Author

meheff commented Feb 23, 2026

One minor change and LGTM.

I would like to remind you too that though we won't go around changing it for no reason the abi of our generated entrypoints shouldn't really be considered stable. We may want to change it dramatically for any number of reasons. Practically the only thing likely to be long term (relatively) stable are the external interfaces our wrapper rules create. For something more long term stable I'd really suggest having an api that you give the entrypoint pointer and metadata and it returns a handle that you can request to execute using some defined 'xls::Value' mirror in the c api. For now though this is fine.

Thanks for the heads up and understood about no guarantee about stability. We're willing to tradeoff stability for performance here (passing in IrValues has some significant performance penalty). Since we don't live at head we can fix things as necessary when they break. We have a wrapper layer in rust which insulates end users from the xls abi details and it should be flexible enough to deal with xls-side changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants