Skip to content

Revise the calling convention of the generated code for _metadata #6758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

steven-johnson
Copy link
Contributor

@steven-johnson steven-johnson commented May 10, 2022

This PR does some groundwork necessary to implement #6757 cleanly:

  • AOT _metadata() getters should be multitarget-aware #6757 uses call_cached_indirect_function to support multitarget cleanliness for metadata getters
  • but, name-mangling in MSVC includes the return type, which is currently halide_filter_metadata_t* for the getter
  • the existing code in Codegen_LLVM assumes that all the functions passed to compile() return int32; while this could probably be generalized, there is potentially a long tail of special-cases to deal with, as I discovered from some experimentation
  • therefore, this changes the generated code of the metadata getetr to match the form of the signature that this expects, ie int foo(args).

Before this, we'd generate an extern func like:

const struct halide_filter_metadata_t * metadata_tester_metadata();

now, we generate an extern func like:

int metadata_tester_get_metadata(const struct halide_filter_metadata_t **md_out);

...along with an inline wrapper using the old name and calling convention so that call sites don't need to change.

This PR does some groundwork necessary to implement #6757 cleanly:
- #6757 uses `call_cached_indirect_function` to support multitarget cleanliness for metadata getters
- but, name-mangling in MSVC includes the return type, which is currently `halide_filter_metadata_t*` for the getter
- the existing code in Codegen_LLVM assumes that all the functions passed to `compile()` return int32; while this *could* probably be generalized, there is potentially a long tail of special-cases to deal with, as I discovered from some experimentation
- therefore, this changes the *generated* code of the metadata getetr to match the form of the signature that this expects, ie `int foo(args)`.

Before this, we'd generate an extern func like:

    const struct halide_filter_metadata_t * metadata_tester_get_metadata();

now, we generate an extern func like:

    int metadata_tester_get_metadata(const struct halide_filter_metadata_t **md_out);

...along with an inline wrapper using the old name and calling convention so that call sites don't need to change.
@steven-johnson steven-johnson requested a review from abadams May 10, 2022 23:17
@steven-johnson steven-johnson marked this pull request as draft May 11, 2022 15:45
@steven-johnson
Copy link
Contributor Author

I'm converting this to a draft PR, because it turns out that inside the can of worms mentioned above lies another, even larger can of worms -- defying space-time somehow -- to wit: our codegen not only expects an int32 return type, it also expects all input/output args to be either scalar or halide_buffer_t, and trying to coerce it to flexibly supporting other things looks to be a nontrivial effort.

I began this mess (along with #6757) on the assumption it would be a quick-n-easy way to assist in some debugging issues, but it manifestly is not, and since there's no compelling need for these changes that I'm aware of, I'm just gonna mothball these here for future reference.

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.

1 participant