-
Notifications
You must be signed in to change notification settings - Fork 751
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
javacpp-presets llvm bitcode example ? #894
Comments
Looks a lot like the following sample. Did you give it at try? |
is these methods removed ? |
No, they were added by @yukoba. |
It is not released yet. You can use them from 1.5.4. |
1.5.4 yes bash cppbuild.sh -platform windows-x86_64 install llvm/d/repo/javacpp-presets /d/repo/javacpp-presets/llvm
to get the value of VCTargetsPath:
Exit code: 1 -- Configuring incomplete, errors occurred! |
No need to build it from source, you can use the snapshots: http://bytedeco.org/builds/ |
Okay nice , and run the function with params and get return values , including pass by pointer . |
@eix128 I've have created a small library to load, compile and run LLVM IR code. You might wanna take a look. Interesting for you should be the LLVMStoredModuleBuilder class. |
@Neiko2002 Thanks , very nice , what about running function ? |
@eix128 Using this library, you create a Java interface containing methods that have the same name and signature as the functions in the LLVM IR code. I have no idea how the generated code form mcsema looks like and how they manage the naming. But you can build an LLVM module and iterate thru all functions it has. Then you can ask for the function name and signature similar to what I did in the LLVMProgram class. |
@Neiko2002 Mcsema is generating LLVM native bitcode. But there is no java equvalient |
@eix128 Sorry I do not get it. Of course, LLVM native bitcode can be run directly with LLVM, that's exactly what my library does. It just adds a layer of type safety. You were asking how to run a native function and I described how to do it with llvm-jnr. But back to you initial topic question. You want to run a "bitcode function inside my java app". Are you looking for an equivalent of your code snipped? Getting a function object from LLVM? Those functions are quite limited that's why saudet suggested using polly. |
Not "polly", maybe you mean "clang" here? BTW, why is it that we cannot always use |
Ah, ok, Well, once we get libc++ in there, we can start using Clang for maximum performance with this :) |
I just said polly, because you pointed him to the polly example in your initial answer of this topic. What he is looking for is more the JNA part of this example or the JNR part in my library, where he can call arbitrary functions with no parameter restrictions like |
BTW, you guys should checkout TVM: https://github.com/bytedeco/javacpp-presets/tree/master/tvm It's pretty awesome. It uses LLVM as its main backend, but it can link with MKL, etc as well, so we get everything in the same framework to get great overall performance like this: Although it's made to compile "deep learning models", it's IR is actually pretty general and we can easily create custom graphs with it's high-level API like this: It's mainly usable from Python (callable from Java with the presets for CPython), but since it's getting pretty stable, they've also started to offer a C++ API, that we can wrap with JavaCPP to use it in Java with callbacks and everything without any Python at all. |
/cc @oneengineer |
@eix128 I remeber @Neiko2002 has several good examples.
|
And here's a good step in the right direction for the generalization of a framework like TVM: |
/cc @supergrecko |
If you'd like I can include a sample that calls a function at a given address using JNA in #1016 I should also add an example that does this for the libgccjit preset. |
@supergrecko No need to, there's already a sample from @yukoba using JNA here: @eix128 Does the new sample code from @supergrecko at pull #1016 answer your original question? BTW, the presets for LLVM now bundle Clang and LLD, and I've also tried to bundle libc++, but it's a bit trickier as it still depends on the native C header files and libraries (glibc on Linux, UCRT on Windows, etc). It seems like it would be hard to come up with something that is fully self-contained as with libffi... :( |
Duplicate of #833 |
FYI, I've added presets for libffi in commit 3075f99, so we can now use that directly at least to avoid any overhead from JNA or JNR. |
Hi ,
There is binary lifter project :
https://github.com/lifting-bits/mcsema
This project generates bitcode from binary.
I want to call bitcode function inside my java app.
I can use bitcode on C++ Like this:
#include <string>
#include <memory>
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ModuleProvider.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/ExecutionEngine/JIT.h>
using namespace std;
using namespace llvm;
int main()
{
InitializeNativeTarget();
llvm_start_multithreaded();
LLVMContext context;
}
How can i use same on javacpp-presets llvm Java ?
file : "bitcode.bc"
method: "foo"
with some params and get return value.
I need example use case
The text was updated successfully, but these errors were encountered: