Skip to content

Commit 2aa1b2f

Browse files
authored
Add llvmeltype helper function. (#288)
1 parent 6db6b91 commit 2aa1b2f

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

src/core/value.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ end
4040

4141
## general APIs
4242

43-
export llvmtype, name, name!, replace_uses!, isconstant, isundef, context
43+
export llvmtype, llvmeltype, name, name!, replace_uses!, isconstant, isundef, context
4444

4545
llvmtype(val::Value) = LLVMType(API.LLVMTypeOf(val))
46+
llvmeltype(val::Value) = eltype(llvmtype(val))
4647

4748
name(val::Value) = unsafe_string(API.LLVMGetValueName(val))
4849
name!(val::Value, name::String) = API.LLVMSetValueName(val, name)

src/core/value/constant.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ register(ConstantAggregateZero, API.LLVMConstantAggregateZeroValueKind)
133133
# array interface
134134
# FIXME: can we reuse the ::ConstantArray functionality with ConstantAggregateZero values?
135135
# probably works fine if we just get rid of the refcheck
136-
Base.eltype(caz::ConstantAggregateZero) = eltype(llvmtype(caz))
136+
Base.eltype(caz::ConstantAggregateZero) = llvmeltype(caz)
137137
Base.size(caz::ConstantAggregateZero) = (0,)
138138
Base.length(caz::ConstantAggregateZero) = 0
139139
Base.axes(caz::ConstantAggregateZero) = (Base.OneTo(0),)
@@ -196,7 +196,7 @@ function Base.collect(ca::ConstantArray)
196196
end
197197

198198
# array interface
199-
Base.eltype(ca::ConstantArray) = eltype(llvmtype(ca))
199+
Base.eltype(ca::ConstantArray) = llvmeltype(ca)
200200
function Base.size(ca::ConstantArray)
201201
dims = Int[]
202202
typ = llvmtype(ca)

src/interop/base.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function Base.convert(::Type{LLVMType}, typ::Type; ctx::Union{Nothing,Context}=n
9191
llvmtyp = let
9292
mod = parse(LLVM.Module, buf; ctx)
9393
gv = first(globals(mod))
94-
eltype(llvmtype(gv))
94+
llvmeltype(gv)
9595
end
9696
end
9797

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ function clone(f::Function; value_map::Dict{Value,Value}=Dict{Value,Value}())
4949
end
5050

5151
# Create a new function type...
52-
vararg = isvararg(eltype(llvmtype(f)))
53-
fty = FunctionType(return_type(eltype(llvmtype(f))), argtypes; vararg)
52+
vararg = isvararg(llvmeltype(f))
53+
fty = FunctionType(return_type(llvmeltype(f)), argtypes; vararg)
5454

5555
# Create the new function...
5656
new_f = Function(parent(f), name(f), fty)

test/core.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ LLVM.Module("SomeModule"; ctx) do mod
10471047

10481048
fn = LLVM.Function(mod, intr)
10491049
@test fn isa LLVM.Function
1050-
@test eltype(llvmtype(fn)) == ft
1050+
@test llvmeltype(fn) == ft
10511051
@test isintrinsic(fn)
10521052

10531053
@test intr == Intrinsic("llvm.trap")
@@ -1074,7 +1074,7 @@ LLVM.Module("SomeModule"; ctx) do mod
10741074

10751075
fn = LLVM.Function(mod, intr, [LLVM.DoubleType(ctx)])
10761076
@test fn isa LLVM.Function
1077-
@test eltype(llvmtype(fn)) == ft
1077+
@test llvmeltype(fn) == ft
10781078
@test isintrinsic(fn)
10791079

10801080
@test intr == Intrinsic("llvm.sin")

0 commit comments

Comments
 (0)