Skip to content

Commit

Permalink
Export Julia's LLVM passes using LLVM C API compatible functions.
Browse files Browse the repository at this point in the history
Used for external language implementations.
  • Loading branch information
maleadt committed Oct 19, 2016
1 parent 3b33217 commit be38529
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
#include <llvm/Analysis/Verifier.h>
#endif

// C API
#if JL_LLVM_VERSION >= 30800
#include <llvm-c/Types.h>
#else
#include <llvm-c/Core.h>
#endif

// for configuration options
#include <llvm/Support/PrettyStackTrace.h>
#include <llvm/Support/CommandLine.h>
Expand Down Expand Up @@ -6222,3 +6229,8 @@ extern "C" void jl_dump_llvm_type(void *v)
{
((Type*)v)->dump(); putchar('\n');
}

extern "C" JL_DLLEXPORT
LLVMValueRef jl_get_tbaa_gcframe() {
return wrap(MetadataAsValue::get(jl_LLVMContext, tbaa_gcframe));
}
2 changes: 2 additions & 0 deletions src/julia.expmap
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
julia_type_to_llvm;
_IO_stdin_used;
__ZN4llvm23createLowerSimdLoopPassEv;
LLVMAddLowerGCFramePass;
LLVMAddLowerPTLSPass;

/* freebsd */
environ;
Expand Down
8 changes: 8 additions & 0 deletions src/llvm-gcroot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <llvm/IR/Instructions.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Intrinsics.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Transforms/Utils/BasicBlockUtils.h>
#if JL_LLVM_VERSION >= 30600
Expand Down Expand Up @@ -1245,3 +1246,10 @@ Pass *createLowerGCFramePass(MDNode *tbaa_gcframe)
assert(tbaa_gcframe);
return new LowerGCFrame(tbaa_gcframe);
}

extern "C" JL_DLLEXPORT
void LLVMAddLowerGCFramePass(LLVMPassManagerRef PM, LLVMValueRef V) {
auto *MD = cast<MetadataAsValue>(unwrap(V));
auto *tbaa_gcframe = cast<MDNode>(MD->getMetadata());
unwrap(PM)->add(createLowerGCFramePass(tbaa_gcframe));
}
8 changes: 8 additions & 0 deletions src/llvm-ptls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/LegacyPassManager.h>

#include "julia.h"
#include "julia_internal.h"
Expand Down Expand Up @@ -203,3 +204,10 @@ Pass *createLowerPTLSPass(bool imaging_mode, MDNode *tbaa_const)
assert(tbaa_const);
return new LowerPTLS(imaging_mode, tbaa_const);
}

extern "C" JL_DLLEXPORT
void LLVMAddLowerPTLSPass(LLVMPassManagerRef PM, LLVMValueRef V, int imaging_mode) {
auto *MD = cast<MetadataAsValue>(unwrap(V));
auto *tbaa_gcframe = cast<MDNode>(MD->getMetadata());
unwrap(PM)->add(createLowerPTLSPass(imaging_mode != 0, tbaa_gcframe));
}

0 comments on commit be38529

Please sign in to comment.