Skip to content

Commit

Permalink
* Annotate the presets for LLVM with @NoException to reduce unneed…
Browse files Browse the repository at this point in the history
…ed C++ overhead (pull #1052)
  • Loading branch information
junlarsen authored Jun 3, 2021
1 parent 231ec19 commit 88236a4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Annotate the presets for LLVM with `@NoException` to reduce unneeded C++ overhead ([pull #1052](https://github.com/bytedeco/javacpp-presets/pull/1052))
* Update samples for LLVM 12 including new `samples/llvm/OrcJit.java` using libffi ([pull #1050](https://github.com/bytedeco/javacpp-presets/pull/1050))
* Enable GTK support in presets for OpenCV when building on ARM as well
* Correct `enum` classes in presets for Spinnaker ([pull #1048](https://github.com/bytedeco/javacpp-presets/pull/1048))
Expand Down
13 changes: 11 additions & 2 deletions llvm/samples/polly/MatMulBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,17 @@ static LLVMModuleRef build() {
return module;
}

static void handleError(LLVMErrorRef e) {
if (e != null && !e.isNull()) {
BytePointer p = LLVMGetErrorMessage(e);
String s = p.getString();
LLVMDisposeErrorMessage(p);
throw new RuntimeException(s);
}
}

static void optimize(LLVMModuleRef module) {
optimizeModule(module, cpu, 3, 0);
handleError(optimizeModule(module, cpu, 3, 0));
}

static void verify(LLVMModuleRef module, boolean dumpModule) {
Expand All @@ -295,7 +304,7 @@ static void verify(LLVMModuleRef module, boolean dumpModule) {
}

static void jitCompile(LLVMExecutionEngineRef engine, LLVMModuleRef module) {
createOptimizedJITCompilerForModule(engine, module, cpu, 3);
handleError(createOptimizedJITCompilerForModule(engine, module, cpu, 3));
}

static LLVMValueRef toConstInt(int v) {
Expand Down
9 changes: 5 additions & 4 deletions llvm/src/gen/java/org/bytedeco/llvm/global/LLVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -11066,19 +11066,20 @@ public static native void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassM
// #include "llvm/Pass.h"
// #include "llvm-c/Transforms/PassManagerBuilder.h"
// #include "llvm-c/Types.h"
// #include "llvm-c/Error.h"

/**
* This function does the standard LLVM optimization.
* This function is based on main() of llvm/tools/opt/opt.cpp.
* Use LLVMGetHostCPUName() for the cpu argument.
*/
public static native void optimizeModule(
public static native LLVMErrorRef optimizeModule(
LLVMModuleRef moduleRef,
@Cast("const char*") BytePointer cpu,
@Cast("unsigned") int optLevel,
@Cast("unsigned") int sizeLevel
);
public static native void optimizeModule(
public static native LLVMErrorRef optimizeModule(
LLVMModuleRef moduleRef,
String cpu,
@Cast("unsigned") int optLevel,
Expand All @@ -11089,13 +11090,13 @@ public static native void optimizeModule(
* This function is similar to LLVMCreateJITCompilerForModule() but does CPU specific optimization.
* Use LLVMGetHostCPUName() for the cpu argument.
*/
public static native void createOptimizedJITCompilerForModule(
public static native LLVMErrorRef createOptimizedJITCompilerForModule(
@ByPtrPtr LLVMExecutionEngineRef outJIT,
LLVMModuleRef moduleRef,
@Cast("const char*") BytePointer cpu,
@Cast("unsigned") int optLevel
);
public static native void createOptimizedJITCompilerForModule(
public static native LLVMErrorRef createOptimizedJITCompilerForModule(
@Cast("LLVMExecutionEngineRef*") PointerPointer outJIT,
LLVMModuleRef moduleRef,
String cpu,
Expand Down
1 change: 1 addition & 0 deletions llvm/src/main/java/org/bytedeco/llvm/presets/LLVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
compiler = "cpp14", link = {"LLVM-12", "LTO@.12", "Remarks@.12"}, resource = {"include", "lib", "libexec", "share"}),
@Platform(value = "macosx", link = {"LLVM", "LTO", "Remarks"}),
@Platform(value = "windows", link = {"LLVM", "LTO", "Remarks"})})
@NoException
public class LLVM implements InfoMapper {
static { Loader.checkVersion("org.bytedeco", "llvm"); }

Expand Down
1 change: 1 addition & 0 deletions llvm/src/main/java/org/bytedeco/llvm/presets/clang.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
include = {"<clang-c/Platform.h>", "<clang-c/CXErrorCode.h>", "<clang-c/CXString.h>", "<clang-c/CXCompilationDatabase.h>",
"<clang-c/BuildSystem.h>", "<clang-c/Index.h>", "<clang-c/Documentation.h>"},
compiler = "cpp14", link = "clang@.12"), @Platform(value = "windows", link = "libclang") })
@NoException
public class clang implements InfoMapper {
public void map(InfoMap infoMap) {
infoMap.put(new Info("LLVM_CLANG_C_EXTERN_C_BEGIN").cppText("#define LLVM_CLANG_C_EXTERN_C_BEGIN").cppTypes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "llvm/Pass.h"
#include "llvm-c/Transforms/PassManagerBuilder.h"
#include "llvm-c/Types.h"
#include "llvm-c/Error.h"

using namespace llvm;

Expand All @@ -45,7 +46,7 @@ using namespace llvm;
* This function is based on main() of llvm/tools/opt/opt.cpp.
* Use LLVMGetHostCPUName() for the cpu argument.
*/
void optimizeModule(
LLVMErrorRef optimizeModule(
LLVMModuleRef moduleRef,
const char* cpu,
unsigned optLevel,
Expand All @@ -60,7 +61,7 @@ void optimizeModule(
.setErrorStr(&error)
.selectTarget());
if (!machine) {
throw std::runtime_error(error);
return wrap(make_error<StringError>(error, inconvertibleErrorCode()));
}

module->setTargetTriple(machine->getTargetTriple().str());
Expand Down Expand Up @@ -98,13 +99,14 @@ void optimizeModule(

passes.add(createVerifierPass());
passes.run(*module);
return LLVMErrorSuccess;
}

/**
* This function is similar to LLVMCreateJITCompilerForModule() but does CPU specific optimization.
* Use LLVMGetHostCPUName() for the cpu argument.
*/
void createOptimizedJITCompilerForModule(
LLVMErrorRef createOptimizedJITCompilerForModule(
LLVMExecutionEngineRef *outJIT,
LLVMModuleRef moduleRef,
const char* cpu,
Expand All @@ -119,10 +121,11 @@ void createOptimizedJITCompilerForModule(
.setErrorStr(&error)
.create();
if (ee == nullptr) {
throw std::runtime_error(error);
return wrap(make_error<StringError>(error, inconvertibleErrorCode()));
}
ee->finalizeObject();
*outJIT = wrap(ee);
return LLVMErrorSuccess;
}

#endif

0 comments on commit 88236a4

Please sign in to comment.