Skip to content

Commit

Permalink
Merge pull request #182 from maleadt/tb/extra_apis
Browse files Browse the repository at this point in the history
Support extra APIs from JuliaLang/julia#35957
  • Loading branch information
maleadt authored May 25, 2020
2 parents 8f50e35 + dfff7b8 commit 50ec1d5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lib/libLLVM_extra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ function LLVMGetSourceLocation(V::LLVMValueRef, index, Name, Filename, Line, Col
end
end

if VERSION >= v"1.5" && !(v"1.6-" <= VERSION < v"1.6.0-DEV.90")
function LLVMExtraAppendToUsed(Mod::LLVMModuleRef, Values, Count)
@apicall(:LLVMExtraAppendToUsed,Cvoid,(LLVMModuleRef,Ptr{LLVMValueRef},Csize_t), Mod, Values, Count)
end

function LLVMExtraAppendToCompilerUsed(Mod::LLVMModuleRef, Values, Count)
@apicall(:LLVMExtraAppendToCompilerUsed,Cvoid,(LLVMModuleRef,Ptr{LLVMValueRef},Csize_t), Mod, Values, Count)
end

function LLVMExtraAddGenericAnalysisPasses(T, PM)
@apicall(:LLVMExtraAddGenericAnalysisPasses, Cvoid, (LLVMPassManagerRef,), PM)
end
end

if libllvm_version >= v"8.0"
@cenum(LLVMDebugEmissionKind,
LLVMDebugEmissionKindNoDebug = 0,
Expand Down
15 changes: 14 additions & 1 deletion src/core/module.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export dispose,
name, name!,
triple, triple!,
datalayout, datalayout!,
context, inline_asm!
context, inline_asm!,
set_used!, set_compiler_used!

# forward definition of Module in src/core/value/constant.jl
reftype(::Type{Module}) = API.LLVMModuleRef
Expand Down Expand Up @@ -56,6 +57,18 @@ inline_asm!(mod::Module, asm::String) =

context(mod::Module) = Context(API.LLVMGetModuleContext(ref(mod)))

if VERSION >= v"1.5" && !(v"1.6-" <= VERSION < v"1.6.0-DEV.90")

set_used!(mod::Module, values::GlobalVariable...) =
API.LLVMExtraAppendToUsed(ref(mod), collect(ref.(values)), length(values))

set_compiler_used!(mod::Module, values::GlobalVariable...) =
API.LLVMExtraAppendToCompilerUsed(ref(mod), collect(ref.(values)), length(values))

else
set_used!(mod::Module, values::GlobalVariable...) = nothing
set_compiler_used!(mod::Module, values::GlobalVariable...) = nothing
end

## type iteration

Expand Down
9 changes: 7 additions & 2 deletions src/targetmachine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ function emit(tm::TargetMachine, mod::Module, filetype::API.LLVMCodeGenFileType,
return nothing
end

add_transform_info!(pm::PassManager, tm::TargetMachine) =
API.LLVMAddAnalysisPasses(ref(tm), ref(pm))
function add_transform_info!(pm::PassManager, tm::Union{Nothing,TargetMachine})
if tm !== nothing
API.LLVMAddAnalysisPasses(ref(tm), ref(pm))
elseif VERSION >= v"1.5" && !(v"1.6-" <= VERSION < v"1.6.0-DEV.90")
API.LLVMExtraAddGenericAnalysisPasses(ref(pm))
end
end
add_library_info!(pm::PassManager, triple::String) =
API.LLVMAddTargetLibraryInfoByTriple(triple, ref(pm))
12 changes: 12 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,18 @@ LLVM.Module("SomeModule", ctx) do mod
threadlocalmode!(gv, LLVM.API.LLVMNotThreadLocal)
@test threadlocalmode(gv) == LLVM.API.LLVMNotThreadLocal

if VERSION >= v"1.5" && !(v"1.6-" <= VERSION < v"1.6.0-DEV.90")
@test !haskey(globals(mod), "llvm.used")
set_used!(mod, gv)
@test haskey(globals(mod), "llvm.used")
unsafe_delete!(mod, globals(mod)["llvm.used"])

@test !haskey(globals(mod), "llvm.compiler.used")
set_compiler_used!(mod, gv)
@test haskey(globals(mod), "llvm.compiler.used")
unsafe_delete!(mod, globals(mod)["llvm.compiler.used"])
end

let gvars = globals(mod)
@test gv in gvars
unsafe_delete!(mod, gv)
Expand Down

0 comments on commit 50ec1d5

Please sign in to comment.