Skip to content

Commit c478a89

Browse files
authored
Support for module metadata (#150)
2 parents 267774d + 4df610e commit c478a89

15 files changed

+87
-34
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
environment:
22
matrix:
3-
- julia_version: 0.7
43
- julia_version: 1.0
4+
- julia_version: 1.1
55
- julia_version: latest
66

77
platform:

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include:
55
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/common.yml'
66
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_v1.0.yml'
77
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_v1.1.yml'
8+
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_v1.2.yml'
89
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_dev.yml'
910
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/coverage_v1.1.yml'
1011

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ os:
55
- osx
66

77
julia:
8-
- 0.7
98
- 1.0
9+
- 1.1
1010
- nightly
1111

1212
notifications:

lib/8.0/libLLVM_common.jl

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -483,26 +483,6 @@ const LLVMErrorSuccess = 0
483483
mutable struct LLVMOpaqueError end
484484
const LLVMErrorRef = Ptr{LLVMOpaqueError}
485485
const LLVMErrorTypeId = Ptr{Cvoid}
486-
# const LLVM_DEFAULT_TARGET_TRIPLE = "x86_64-linux-gnu"
487-
# const LLVM_ENABLE_THREADS = 1
488-
# const LLVM_HAS_ATOMICS = 1
489-
# const LLVM_HOST_TRIPLE = "x86_64-linux-gnu"
490-
# const LLVM_NATIVE_ARCH = X86
491-
# const LLVM_NATIVE_ASMPARSER = LLVMInitializeX86AsmParser
492-
# const LLVM_NATIVE_ASMPRINTER = LLVMInitializeX86AsmPrinter
493-
# const LLVM_NATIVE_DISASSEMBLER = LLVMInitializeX86Disassembler
494-
# const LLVM_NATIVE_TARGET = LLVMInitializeX86Target
495-
# const LLVM_NATIVE_TARGETINFO = LLVMInitializeX86TargetInfo
496-
# const LLVM_NATIVE_TARGETMC = LLVMInitializeX86TargetMC
497-
# const LLVM_ON_UNIX = 1
498-
# const LLVM_USE_INTEL_JITEVENTS = 0
499-
# const LLVM_USE_OPROFILE = 0
500-
# const LLVM_USE_PERF = 0
501-
# const LLVM_VERSION_MAJOR = 8
502-
# const LLVM_VERSION_MINOR = 0
503-
# const LLVM_VERSION_PATCH = 0
504-
# const LLVM_VERSION_STRING = "8.0.0"
505-
# const LLVM_FORCE_ENABLE_STATS = 0
506486

507487
# Skipping MacroDefinition: LLVM_TARGET ( TargetName ) void LLVMInitialize ## TargetName ## TargetInfo ( void ) ;
508488
# Skipping MacroDefinition: LLVM_TARGET ( TargetName ) void LLVMInitialize ## TargetName ## Target ( void ) ;

lib/libLLVM_extra.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ end
9494

9595
else
9696

97-
if LLVM.libllvm_version < v"8.0.0"
97+
if libllvm_version < v"8.0"
9898

9999
function LLVMAddNVVMReflectPass(PM::LLVMPassManagerRef, smversion)
100100
@apicall(:LLVMExtraAddNVVMReflectPass,Cvoid,(LLVMPassManagerRef,), PM)
@@ -161,3 +161,12 @@ function LLVMGetSourceLocation(V::LLVMValueRef, index, Name, Filename, Line, Col
161161
end
162162

163163
end
164+
165+
if libllvm_version >= v"8.0"
166+
@cenum(LLVMDebugEmissionKind,
167+
LLVMDebugEmissionKindNoDebug = 0,
168+
LLVMDebugEmissionKindFullDebug = 1,
169+
LLVMDebugEmissionKindLineTablesOnly = 2,
170+
LLVMDebugEmissionKindDebugDirectivesOnly = 3,
171+
)
172+
end

src/core/instructions.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ predicate_real(inst::Instruction) = API.LLVMGetFCmpPredicate(ref(inst))
4545

4646

4747
## metadata iteration
48+
# TODO: doesn't actually iterate, since we can't list the available keys
4849

4950
@enum(MD, MD_dbg = 0,
5051
MD_tbaa = 1,
@@ -72,8 +73,6 @@ predicate_real(inst::Instruction) = API.LLVMGetFCmpPredicate(ref(inst))
7273

7374
export InstructionMetadataDict
7475

75-
# doesn't print, because we don't have length. we can't iterate keys?
76-
7776
struct InstructionMetadataDict <: AbstractDict{MD,MetadataAsValue}
7877
inst::Instruction
7978
end

src/core/metadata.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export MDString, MDNode, operands
1+
export MDString, MDNode, operands, Metadata
22

33
@checked struct MetadataAsValue <: Value
44
ref::reftype(Value)
@@ -12,7 +12,7 @@ const MDString = MetadataAsValue
1212

1313
MDString(val::String) = MDString(API.LLVMMDString(val, Cuint(length(val))))
1414

15-
MDString(val::String, ctx::Context) =
15+
MDString(val::String, ctx::Context) =
1616
MDString(API.LLVMMDStringInContext(ref(ctx), val, Cuint(length(val))))
1717

1818
function Base.convert(::Type{String}, md::MDString)
@@ -38,3 +38,17 @@ function operands(md::MDNode)
3838
API.LLVMGetMDNodeOperands(ref(md), ops)
3939
return Value[Value(op) for op in ops]
4040
end
41+
42+
43+
@checked struct Metadata
44+
ref::API.LLVMMetadataRef
45+
end
46+
reftype(::Type{Metadata}) = API.LLVMMetadataRef
47+
48+
function Metadata(val::Value)
49+
return Metadata(LLVM.API.LLVMValueAsMetadata(ref(val)))
50+
end
51+
52+
function Value(md::Metadata, ctx::Context)
53+
return MetadataAsValue(API.LLVMMetadataAsValue(ref(ctx), ref(md)))
54+
end

src/core/module.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,31 @@ function Base.getindex(iter::ModuleFunctionSet, name::String)
176176
objref == C_NULL && throw(KeyError(name))
177177
return Function(objref)
178178
end
179+
180+
181+
## module flag iteration
182+
# TODO: doesn't actually iterate, since we can't list the available keys
183+
184+
if libllvm_version >= v"8.0"
185+
186+
export flags
187+
188+
struct ModuleFlagDict <: AbstractDict{String,Metadata}
189+
mod::Module
190+
end
191+
192+
flags(mod::Module) = ModuleFlagDict(mod)
193+
194+
Base.haskey(iter::ModuleFlagDict, name::String) =
195+
API.LLVMGetModuleFlag(ref(iter.mod), name, length(name)) != C_NULL
196+
197+
function Base.getindex(iter::ModuleFlagDict, name::String)
198+
objref = API.LLVMGetModuleFlag(ref(iter.mod), name, length(name))
199+
objref == C_NULL && throw(KeyError(name))
200+
return Metadata(objref)
201+
end
202+
203+
Base.push!(iter::ModuleFlagDict, behavior::LLVM.API.LLVMModuleFlagBehavior, name::String, val::Metadata) =
204+
API.LLVMAddModuleFlag(ref(iter.mod), behavior, name, length(name), ref(val))
205+
206+
end

src/core/value/constant.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export GlobalValue,
151151
unnamed_addr, unnamed_addr!,
152152
alignment, alignment!
153153

154-
parent(val::GlobalValue) = LLVM.Module(API.LLVMGetGlobalParent(ref(val)))
154+
parent(val::GlobalValue) = Module(API.LLVMGetGlobalParent(ref(val)))
155155

156156
isdeclaration(val::GlobalValue) = convert(Core.Bool, API.LLVMIsDeclaration(ref(val)))
157157

src/debuginfo.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ export DEBUG_METADATA_VERSION, strip_debuginfo!
33
DEBUG_METADATA_VERSION() = API.LLVMDebugMetadataVersion()
44

55
strip_debuginfo!(mod::Module) = API.LLVMStripModuleDebugInfo(ref(mod))
6+
7+
if libllvm_version >= v"8.0"
8+
set_subprogram!(func::Function, sp::Metadata) = LLVM.API.LLVMSetSubprogram(ref(func), ref(sp))
9+
get_subprogram(func::Function) = Metadata(LLVM.API.LLVMGetSubprogram(ref(func)))
10+
end

0 commit comments

Comments
 (0)