Skip to content

Commit

Permalink
Added info that ORC is newer than MCJIT to the readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
Minding000 committed May 16, 2024
1 parent b5ab324 commit ce33955
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions llvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ We can use [Maven 3](http://maven.apache.org/) to download and install automatic

### The `Factorial.java` source file

This example is based on MCJIT. There is a newer alternative called ORC. You can find an example using ORC [here](samples/llvm/OrcJit.java).

```java
import org.bytedeco.javacpp.*;
import org.bytedeco.llvm.LLVM.*;
Expand All @@ -73,11 +75,8 @@ public class Factorial {

public static void main(String[] args) {
// Stage 1: Initialize LLVM components
LLVMInitializeCore(LLVMGetGlobalPassRegistry());
LLVMLinkInMCJIT();
LLVMInitializeNativeAsmPrinter();
LLVMInitializeNativeAsmParser();
LLVMInitializeNativeTarget();
LLVMInitializeNativeTarget();
LLVMInitializeNativeAsmPrinter();

// Stage 2: Build the factorial function.
LLVMContextRef context = LLVMContextCreate();
Expand Down Expand Up @@ -119,6 +118,9 @@ public class Factorial {
LLVMAddIncoming(phi, phiValues, phiBlocks, /* pairCount */ 2);
LLVMBuildRet(builder, phi);

// Print generated LLVM-IR to console (optional)
LLVMDumpModule(module);

// Stage 3: Verify the module using LLVMVerifier
if (LLVMVerifyModule(module, LLVMPrintMessageAction, error) != 0) {
LLVMDisposeMessage(error);
Expand All @@ -127,11 +129,7 @@ public class Factorial {

// Stage 4: Create a pass pipeline using the legacy pass manager
LLVMPassManagerRef pm = LLVMCreatePassManager();
LLVMAddAggressiveInstCombinerPass(pm);
LLVMAddNewGVNPass(pm);
LLVMAddCFGSimplificationPass(pm);
LLVMRunPassManager(pm, module);
LLVMDumpModule(module);

// Stage 5: Execute the code using MCJIT
LLVMExecutionEngineRef engine = new LLVMExecutionEngineRef();
Expand All @@ -145,8 +143,8 @@ public class Factorial {
LLVMGenericValueRef argument = LLVMCreateGenericValueOfInt(i32Type, 10, /* signExtend */ 0);
LLVMGenericValueRef result = LLVMRunFunction(engine, factorial, /* argumentCount */ 1, argument);
System.out.println();
System.out.println("; Running factorial(10) with MCJIT...");
System.out.println("; Result: " + LLVMGenericValueToInt(result, /* signExtend */ 0));
System.out.println("Running factorial(10) with MCJIT...");
System.out.println("Result: " + LLVMGenericValueToInt(result, /* signExtend */ 0));

// Stage 6: Dispose of the allocated resources
LLVMDisposeExecutionEngine(engine);
Expand Down

0 comments on commit ce33955

Please sign in to comment.