Skip to content

Commit 50ec1d5

Browse files
authored
Merge pull request #182 from maleadt/tb/extra_apis
Support extra APIs from JuliaLang/julia#35957
2 parents 8f50e35 + dfff7b8 commit 50ec1d5

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

lib/libLLVM_extra.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ function LLVMGetSourceLocation(V::LLVMValueRef, index, Name, Filename, Line, Col
166166
end
167167
end
168168

169+
if VERSION >= v"1.5" && !(v"1.6-" <= VERSION < v"1.6.0-DEV.90")
170+
function LLVMExtraAppendToUsed(Mod::LLVMModuleRef, Values, Count)
171+
@apicall(:LLVMExtraAppendToUsed,Cvoid,(LLVMModuleRef,Ptr{LLVMValueRef},Csize_t), Mod, Values, Count)
172+
end
173+
174+
function LLVMExtraAppendToCompilerUsed(Mod::LLVMModuleRef, Values, Count)
175+
@apicall(:LLVMExtraAppendToCompilerUsed,Cvoid,(LLVMModuleRef,Ptr{LLVMValueRef},Csize_t), Mod, Values, Count)
176+
end
177+
178+
function LLVMExtraAddGenericAnalysisPasses(T, PM)
179+
@apicall(:LLVMExtraAddGenericAnalysisPasses, Cvoid, (LLVMPassManagerRef,), PM)
180+
end
181+
end
182+
169183
if libllvm_version >= v"8.0"
170184
@cenum(LLVMDebugEmissionKind,
171185
LLVMDebugEmissionKindNoDebug = 0,

src/core/module.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ export dispose,
44
name, name!,
55
triple, triple!,
66
datalayout, datalayout!,
7-
context, inline_asm!
7+
context, inline_asm!,
8+
set_used!, set_compiler_used!
89

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

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

60+
if VERSION >= v"1.5" && !(v"1.6-" <= VERSION < v"1.6.0-DEV.90")
61+
62+
set_used!(mod::Module, values::GlobalVariable...) =
63+
API.LLVMExtraAppendToUsed(ref(mod), collect(ref.(values)), length(values))
64+
65+
set_compiler_used!(mod::Module, values::GlobalVariable...) =
66+
API.LLVMExtraAppendToCompilerUsed(ref(mod), collect(ref.(values)), length(values))
67+
68+
else
69+
set_used!(mod::Module, values::GlobalVariable...) = nothing
70+
set_compiler_used!(mod::Module, values::GlobalVariable...) = nothing
71+
end
5972

6073
## type iteration
6174

src/targetmachine.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ function emit(tm::TargetMachine, mod::Module, filetype::API.LLVMCodeGenFileType,
6464
return nothing
6565
end
6666

67-
add_transform_info!(pm::PassManager, tm::TargetMachine) =
68-
API.LLVMAddAnalysisPasses(ref(tm), ref(pm))
67+
function add_transform_info!(pm::PassManager, tm::Union{Nothing,TargetMachine})
68+
if tm !== nothing
69+
API.LLVMAddAnalysisPasses(ref(tm), ref(pm))
70+
elseif VERSION >= v"1.5" && !(v"1.6-" <= VERSION < v"1.6.0-DEV.90")
71+
API.LLVMExtraAddGenericAnalysisPasses(ref(pm))
72+
end
73+
end
6974
add_library_info!(pm::PassManager, triple::String) =
7075
API.LLVMAddTargetLibraryInfoByTriple(triple, ref(pm))

test/core.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,18 @@ LLVM.Module("SomeModule", ctx) do mod
442442
threadlocalmode!(gv, LLVM.API.LLVMNotThreadLocal)
443443
@test threadlocalmode(gv) == LLVM.API.LLVMNotThreadLocal
444444

445+
if VERSION >= v"1.5" && !(v"1.6-" <= VERSION < v"1.6.0-DEV.90")
446+
@test !haskey(globals(mod), "llvm.used")
447+
set_used!(mod, gv)
448+
@test haskey(globals(mod), "llvm.used")
449+
unsafe_delete!(mod, globals(mod)["llvm.used"])
450+
451+
@test !haskey(globals(mod), "llvm.compiler.used")
452+
set_compiler_used!(mod, gv)
453+
@test haskey(globals(mod), "llvm.compiler.used")
454+
unsafe_delete!(mod, globals(mod)["llvm.compiler.used"])
455+
end
456+
445457
let gvars = globals(mod)
446458
@test gv in gvars
447459
unsafe_delete!(mod, gv)

0 commit comments

Comments
 (0)