Skip to content

Commit ba5c2e5

Browse files
committed
Rename llvmtype to value_type, remove llvmeltype.
1 parent 1205905 commit ba5c2e5

File tree

8 files changed

+33
-34
lines changed

8 files changed

+33
-34
lines changed

src/core/value.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ end
3939

4040
## general APIs
4141

42-
export llvmtype, llvmeltype, name, name!, replace_uses!, replace_metadata_uses!, isconstant, isundef, ispoison, context
42+
export value_type, name, name!, replace_uses!, replace_metadata_uses!, isconstant, isundef, ispoison, context
4343

44-
llvmtype(val::Value) = LLVMType(API.LLVMTypeOf(val))
45-
llvmeltype(val::Value) = eltype(llvmtype(val))
44+
value_type(val::Value) = LLVMType(API.LLVMTypeOf(val))
4645

4746
# defer size queries to the LLVM type (where we'll error)
48-
Base.sizeof(val::Value) = sizeof(llvmtype(val))
47+
Base.sizeof(val::Value) = sizeof(value_type(val))
4948

5049
name(val::Value) = unsafe_string(API.LLVMGetValueName(val))
5150
name!(val::Value, name::String) = API.LLVMSetValueName(val, name)
@@ -58,13 +57,13 @@ end
5857
replace_uses!(old::Value, new::Value) = API.LLVMReplaceAllUsesWith(old, new)
5958

6059
function replace_metadata_uses!(old::Value, new::Value)
61-
if llvmtype(old) == llvmtype(new)
60+
if value_type(old) == value_type(new)
6261
API.LLVMReplaceAllMetadataUsesWith(old, new)
6362
else
6463
# NOTE: LLVM does not support replacing values of different types, either using
6564
# regular RAUW or only on metadata. The latter should probably be supported.
6665
# Instead, we replace by a bitcast to the old type.
67-
compat_new = const_bitcast(new, llvmtype(old))
66+
compat_new = const_bitcast(new, value_type(old))
6867
replace_metadata_uses!(old, compat_new)
6968

7069
# the above is often invalid, e.g. for module-level metadata identifying functions.

src/core/value/constant.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ abstract type ConstantDataSequential <: Constant end
133133
# but cannot support that as explained above).
134134

135135
# array interface
136-
Base.eltype(cda::ConstantDataSequential) = llvmeltype(cda)
137-
Base.length(cda::ConstantDataSequential) = length(llvmtype(cda))
136+
Base.eltype(cda::ConstantDataSequential) = eltype(value_type(cda))
137+
Base.length(cda::ConstantDataSequential) = length(value_type(cda))
138138
Base.size(cda::ConstantDataSequential) = (length(cda),)
139139
function Base.getindex(cda::ConstantDataSequential, idx::Integer)
140140
@boundscheck 1 <= idx <= length(cda) || throw(BoundsError(cda, idx))
@@ -191,7 +191,7 @@ register(ConstantAggregateZero, API.LLVMConstantAggregateZeroValueKind)
191191
# array interface
192192
# FIXME: can we reuse the ::ConstantArray functionality with ConstantAggregateZero values?
193193
# probably works fine if we just get rid of the refcheck
194-
Base.eltype(caz::ConstantAggregateZero) = llvmeltype(caz)
194+
Base.eltype(caz::ConstantAggregateZero) = eltype(value_type(caz))
195195
Base.size(caz::ConstantAggregateZero) = (0,)
196196
Base.length(caz::ConstantAggregateZero) = 0
197197
Base.axes(caz::ConstantAggregateZero) = (Base.OneTo(0),)
@@ -215,15 +215,15 @@ register(ConstantArray, API.LLVMConstantArrayValueKind)
215215

216216
# generic constructor taking an array of constants
217217
function ConstantArray(typ::LLVMType, data::AbstractArray{T,N}=T[]) where {T<:Constant,N}
218-
@assert all(x->x==typ, llvmtype.(data))
218+
@assert all(x->x==typ, value_type.(data))
219219

220220
if N == 1
221221
# XXX: this can return a ConstDataArray (presumably as an optimization?)
222222
return Value(API.LLVMConstArray(typ, Array(data), length(data)))
223223
end
224224

225225
ca_vec = map(x->ConstantArray(typ, x), eachslice(data, dims=1))
226-
ca_typ = llvmtype(first(ca_vec))
226+
ca_typ = value_type(first(ca_vec))
227227

228228
return ConstantArray(API.LLVMConstArray(ca_typ, ca_vec, length(ca_vec)))
229229
end
@@ -252,10 +252,10 @@ function Base.collect(ca::ConstantArray)
252252
end
253253

254254
# array interface
255-
Base.eltype(ca::ConstantArray) = llvmeltype(ca)
255+
Base.eltype(ca::ConstantArray) = eltype(value_type(ca))
256256
function Base.size(ca::ConstantArray)
257257
dims = Int[]
258-
typ = llvmtype(ca)
258+
typ = value_type(ca)
259259
while typ isa ArrayType
260260
push!(dims, length(typ))
261261
typ = eltype(typ)
@@ -326,13 +326,13 @@ function ConstantStruct(value::T, name=String(nameof(T)); ctx::Context,
326326
ConstantStruct(constants; ctx, packed)
327327
elseif haskey(types(ctx), name)
328328
typ = types(ctx)[name]
329-
if collect(elements(typ)) != llvmtype.(constants)
330-
throw(ArgumentError("Cannot create struct $name {$(join(llvmtype.(constants), ", "))} as it is already defined in this context as {$(join(elements(typ), ", "))}."))
329+
if collect(elements(typ)) != value_type.(constants)
330+
throw(ArgumentError("Cannot create struct $name {$(join(value_type.(constants), ", "))} as it is already defined in this context as {$(join(elements(typ), ", "))}."))
331331
end
332332
ConstantStruct(typ, constants)
333333
else
334334
typ = StructType(name; ctx)
335-
elements!(typ, llvmtype.(constants))
335+
elements!(typ, value_type.(constants))
336336
ConstantStruct(typ, constants)
337337
end
338338
end

src/interop/base.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function Base.convert(::Type{LLVMType}, typ::Type; ctx::Context,
109109
llvmtyp = let
110110
mod = parse(LLVM.Module, buf; ctx)
111111
gv = first(globals(mod))
112-
llvmeltype(gv)
112+
eltype(value_type(gv))
113113
end
114114
end
115115

src/irbuilder.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ debuglocation!(builder::Builder, inst::Instruction) =
5555
## build methods
5656

5757
# TODO/IDEAS:
58-
# - dynamic dispatch based on `llvmtype` (eg. disambiguating `add!` and `fadd!`)
58+
# - dynamic dispatch based on `value_type` (eg. disambiguating `add!` and `fadd!`)
5959

6060
# NOTE: the return values for these operations are, according to the C API, always a Value.
6161
# however, the C++ API learns us that we can be more strict.

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function clone(f::Function; value_map::Dict{Value,Value}=Dict{Value,Value}())
5050
# the VMap. If so, we need to not add the arguments to the arg ty vector
5151
for arg in parameters(f)
5252
if !in(arg, keys(value_map)) # Haven't mapped the argument to anything yet?
53-
push!(argtypes, llvmtype(arg))
53+
push!(argtypes, value_type(arg))
5454
end
5555
end
5656

test/core.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ end
228228

229229
show(devnull, val)
230230

231-
@test llvmtype(val) == LLVM.PointerType(typ)
231+
@test value_type(val) == LLVM.PointerType(typ)
232232
@test_throws ErrorException sizeof(val)
233233
@test name(val) == "foo"
234234
@test !isconstant(val)
@@ -367,7 +367,7 @@ end
367367
end
368368
let
369369
constval = ConstantInt(false; ctx)
370-
@test llvmtype(constval) == LLVM.Int1Type(ctx)
370+
@test value_type(constval) == LLVM.Int1Type(ctx)
371371
@test !convert(Bool, constval)
372372

373373
constval = ConstantInt(true; ctx)
@@ -459,7 +459,7 @@ end
459459
let
460460
test_struct = TestStruct(true, -99, 1.5)
461461
constant_struct = ConstantStruct(test_struct; ctx, anonymous=true)
462-
constant_struct_type = llvmtype(constant_struct)
462+
constant_struct_type = value_type(constant_struct)
463463

464464
@test constant_struct_type isa LLVM.StructType
465465
@test context(constant_struct) == ctx
@@ -479,7 +479,7 @@ end
479479
let
480480
test_struct = TestStruct(false, 52, -2.5)
481481
constant_struct = ConstantStruct(test_struct; ctx)
482-
constant_struct_type = llvmtype(constant_struct)
482+
constant_struct_type = value_type(constant_struct)
483483

484484
@test constant_struct_type isa LLVM.StructType
485485

@@ -499,7 +499,7 @@ end
499499
let
500500
test_struct = TestSingleton()
501501
constant_struct = ConstantStruct(test_struct; ctx)
502-
constant_struct_type = llvmtype(constant_struct)
502+
constant_struct_type = value_type(constant_struct)
503503

504504
@test isempty(operands(constant_struct))
505505
end
@@ -517,7 +517,7 @@ end
517517
eltyp = LLVM.Int32Type(ctx)
518518
cda = ConstantDataArray(eltyp, vec)
519519
@test cda isa ConstantDataArray
520-
@test llvmtype(cda) == LLVM.ArrayType(eltyp, 4)
520+
@test value_type(cda) == LLVM.ArrayType(eltyp, 4)
521521
@test collect(cda) == ConstantInt.(vec; ctx)
522522
end
523523

@@ -697,7 +697,7 @@ end
697697
ce = const_ptrtoint(ptr, LLVM.Int32Type(ctx))::LLVM.Constant
698698
@check_ir ce "i32 0"
699699

700-
ce = const_inttoptr(ce, llvmtype(ptr))::LLVM.Constant
700+
ce = const_inttoptr(ce, value_type(ptr))::LLVM.Constant
701701
if supports_typed_ptrs
702702
@check_ir ce "i32* null"
703703
else
@@ -815,7 +815,7 @@ end
815815
@dispose ctx=Context() mod=LLVM.Module("SomeModule"; ctx) begin
816816
gv = GlobalVariable(mod, LLVM.Int32Type(ctx), "SomeGlobal", 1)
817817

818-
@test addrspace(llvmtype(gv)) == 1
818+
@test addrspace(value_type(gv)) == 1
819819
end
820820

821821
end
@@ -1165,7 +1165,7 @@ end
11651165
@test fn isa LLVM.Function
11661166

11671167
if supports_typed_ptrs
1168-
@test llvmeltype(fn) == ft
1168+
@test eltype(value_type(fn)) == ft
11691169
end
11701170
@test isintrinsic(fn)
11711171

@@ -1192,7 +1192,7 @@ end
11921192
fn = LLVM.Function(mod, intr, [LLVM.DoubleType(ctx)])
11931193
@test fn isa LLVM.Function
11941194
if supports_typed_ptrs
1195-
@test llvmeltype(fn) == ft
1195+
@test eltype(value_type(fn)) == ft
11961196
end
11971197
@test isintrinsic(fn)
11981198

test/instructions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
@check_ir bitcastinst "bitcast i32 %0 to float"
274274
if supports_typed_ptrs
275275
i32ptr1 = parameters(fn)[5]
276-
i32ptr1typ = llvmtype(i32ptr1)
276+
i32ptr1typ = value_type(i32ptr1)
277277
i32ptr1typ2 = LLVM.PointerType(eltype(i32ptr1typ), 2)
278278
addrspacecastinst = addrspacecast!(builder, i32ptr1, i32ptr1typ2)
279279
@check_ir addrspacecastinst "addrspacecast i32* %4 to i32 addrspace(2)*"

test/utils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# basic clone
2929
let new_f = clone(f)
3030
@test new_f != f
31-
@test llvmtype(new_f) == llvmtype(f)
31+
@test value_type(new_f) == value_type(f)
3232
for (bb1, bb2) in zip(blocks(f), blocks(new_f))
3333
for (inst1, inst2) in zip(instructions(bb2), instructions(bb2))
3434
@test inst1 == inst2
@@ -85,9 +85,9 @@
8585

8686
# the add should now be a 64-bit addition
8787
add = first(instructions(first(blocks(new_f))))
88-
@test llvmtype(operands(add)[1]) == LLVM.Int64Type(ctx)
89-
@test llvmtype(operands(add)[2]) == LLVM.Int64Type(ctx)
90-
@test llvmtype(add) == LLVM.Int64Type(ctx)
88+
@test value_type(operands(add)[1]) == LLVM.Int64Type(ctx)
89+
@test value_type(operands(add)[2]) == LLVM.Int64Type(ctx)
90+
@test value_type(add) == LLVM.Int64Type(ctx)
9191
end
9292
end
9393
end

0 commit comments

Comments
 (0)