Skip to content
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

Missing LLVM Target Initialization APIs #935

Closed
junlarsen opened this issue Aug 24, 2020 · 4 comments
Closed

Missing LLVM Target Initialization APIs #935

junlarsen opened this issue Aug 24, 2020 · 4 comments

Comments

@junlarsen
Copy link
Member

junlarsen commented Aug 24, 2020

Partially related to #932

In the llvm-c/Target.h header there are six macros which declare functions for target initialization. These are ran for each target to generate a set of APIs exposed to LLVM-C.

Javacpp is currently not properly read though this (probably because the llvm/Config/Targets.def file is created during build generation.

Fix

I'm not sure how we want to go about adding these APIs as they should only be available if the target is enabled. With the current build setup, that would be one target, but a different one for each platform we build the binaries for.

  1. Creating a stub file (similar to LLVM full optimization #869) in the resources directory and add it to the preset for ALL targets
    This solution means that the initialization API for every target will be "available" regardless of which target the user's binary has enabled. This is probably not wanted behavior because calling into a function which doesn't actually exist will crash the JVM.

  2. Parse the llvm-c/Target.h file after build generator step, assuming the Javacpp parser is able to perform macro expansion.
    This requires the parser to go over the files after the build has been generated.

I have created an example showing how this could be done if we go with option 1 here

@saudet
Copy link
Member

saudet commented Aug 25, 2020

Is there a reason why the LLVMInitializeAllTargets(), etc functions not enough?

@junlarsen
Copy link
Member Author

Generally yeah, they're more than enough. I just noticed they were missing from the javacpp output and wanted to raise awareness. There would be some unnecessary initalization if one doesn't use all the targets, but it's a very minor thing.

@saudet
Copy link
Member

saudet commented Aug 25, 2020

The problem isn't macro expansion, it's because JavaCPP doesn't process #include directives, the idea being that users best know in what order they should be parsed, but it doesn't work when the same file is included multiple times in another file like this with different macro values.

@saudet
Copy link
Member

saudet commented Sep 10, 2020

Released with version 1.5.4! Thank you for your contribution

@saudet saudet closed this as completed Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants