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

Update LLVM examples for LLVM 12 and libffi #1050

Merged
merged 10 commits into from
Jun 3, 2021

Conversation

junlarsen
Copy link
Member

@junlarsen junlarsen commented May 24, 2021

As mentioned in #833 I have updated the LLVM samples.

Changes in this patch:
  1. Moved the different samples into their own directories. It quickly becomes confusing which files are related to each other, especially when the EmitBitcode example is 2 Java files.
  2. Updated Factorial sample for LLVM 12 - one of the passes that sample used is now gone, so the old one wouldn't compile.
    • I will also be updating this sample to use the bindings for the new LLVM pass manager which I recently landed upstream when LLVM 13 releases.
  3. Added steps for each sample describing what each step does. It was previously a bit difficult to differentiate between what each line of code was used for.
  4. Added a new sample using the new OrcJIT v2 API which was added in LLVM 12. This uses the new libffi preset to call the JIT'ed functions

I suppose we should also change the sample code shown in llvm/README.md.

I also thought about adding the samples to CI so we're sure the samples still run when we update code.

Let me know what you think.

@saudet
Copy link
Member

saudet commented May 25, 2021

As mentioned in #833 I have updated the LLVM samples.

Changes in this patch:
  1. Moved the different samples into their own directories. It quickly becomes confusing which files are related to each other, especially when the EmitBitcode example is 2 Java files.

I find that splitting everything up in multiple directories make things more complicated. @Neiko2002 Did it for LLVM vs Clang, and @yukoba did it for Polly, which is not too confusing because those correspond to different LLVM modules, but I'm not following what the benefit is for the changes proposed here. Isn't there a way to make each sample stand alone? They are not even 100 lines long. Why do they need to be related to each other? If you're trying to create a structure for some high-level API, that code could be better placed as part of another project like LLVM4J (whose repository you could move under this organization if you wished BTW).

  1. Updated Factorial sample for LLVM 12 - one of the passes that sample used is now gone, so the old one wouldn't compile.

    • I will also be updating this sample to use the bindings for the new LLVM pass manager which I recently landed upstream when LLVM 13 releases.
  2. Added steps for each sample describing what each step does. It was previously a bit difficult to differentiate between what each line of code was used for.

  3. Added a new sample using the new OrcJIT v2 API which was added in LLVM 12. This uses the new libffi preset to call the JIT'ed functions

I suppose we should also change the sample code shown in llvm/README.md.

I also thought about adding the samples to CI so we're sure the samples still run when we update code.

Let me know what you think.

The rest sounds good. 👍 FYI, running samples would only work for builds that do not use a cross compiler, in other words probably only linux-x86_64, macosx-x86_64, and windows-x86_64.

@junlarsen
Copy link
Member Author

junlarsen commented May 25, 2021

Thank you for the feedback, I figured a module for each sample would be easier to follow, but if you prefer to keep it as is, then I'm good with that. I will also merge the Bitcode samples into a single file.

The rest sounds good. 👍 FYI, running samples would only work for builds that do not use a cross compiler, in other words probably only linux-x86_64, macosx-x86_64, and windows-x86_64.

Yeah that sounds about right. I'll add a ci build for those environments.

commit 4c2cf5b9e6b896b5fbf6898ff2552ba6de591fe8
Author: Mats Larsen <me@supergrecko.com>
Date:   Tue May 25 10:44:02 2021 +0200

    Undo separating samples into their own modules
@junlarsen
Copy link
Member Author

junlarsen commented May 25, 2021

Went ahead and implemented running the various samples with Maven profiles which will conditionally set the exec.mainClass

Edit: having some issues with macos and the libffi sample: https://github.com/supergrecko/javacpp-presets/runs/2663909894

@saudet
Copy link
Member

saudet commented May 27, 2021

Ah, yes, we need to hack the rpath with Autoconf on Mac. Try with this patch:

--- a/libffi/cppbuild.sh
+++ b/libffi/cppbuild.sh
@@ -84,6 +84,7 @@ case $PLATFORM in
         make install-strip
         ;;
     macosx-*)
+        sedinplace 's/\\\$rpath/@rpath/g' configure
         CC="clang" ./configure --prefix="$INSTALL_PATH" --disable-multi-os-directory
         make -j $MAKEJ
         make install-strip

@junlarsen
Copy link
Member Author

Ah, yes, we need to hack the rpath with Autoconf on Mac. Try with this patch:

--- a/libffi/cppbuild.sh
+++ b/libffi/cppbuild.sh
@@ -84,6 +84,7 @@ case $PLATFORM in
         make install-strip
         ;;
     macosx-*)
+        sedinplace 's/\\\$rpath/@rpath/g' configure
         CC="clang" ./configure --prefix="$INSTALL_PATH" --disable-multi-os-directory
         make -j $MAKEJ
         make install-strip

The samples run off of the libffi packages which are on Sonatype OSS, shouldn't that patch be merged upstream first (or is it not supposed to be)?

@saudet
Copy link
Member

saudet commented May 28, 2021

Sure, I've applied the patch in commit 82b9be7 and updated snapshots are up.

@junlarsen
Copy link
Member Author

libffi seems to be working - getting a segfault in the sample on macos, will investigate.

The ThreadSafeModule is moved into the LLJIT which takes care of it from there. We should not need to delete it ourselves.
@junlarsen
Copy link
Member Author

libffi seems to be working - getting a segfault in the sample on macos, will investigate.

This should be fixed now. Let me know if there's anything else.

@saudet saudet merged commit 231ec19 into bytedeco:master Jun 3, 2021
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.

None yet

2 participants