Skip to content

Support extra APIs from JuliaLang/julia#35957 #182

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

Merged
merged 1 commit into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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