@@ -250,7 +250,7 @@ function lower_throw!(mod::LLVM.Module)
250
250
call = user (use):: LLVM.CallInst
251
251
252
252
# replace the throw with a PTX-compatible exception
253
- @dispose builder= Builder (ctx) begin
253
+ @dispose builder= IRBuilder (ctx) begin
254
254
position! (builder, call)
255
255
emit_exception! (builder, name, call)
256
256
end
@@ -330,12 +330,13 @@ end
330
330
331
331
function emit_trap! (@nospecialize (job:: CompilerJob ), builder, mod, inst)
332
332
ctx = context (mod)
333
+ trap_ft = LLVM. FunctionType (LLVM. VoidType (ctx))
333
334
trap = if haskey (functions (mod), " llvm.trap" )
334
335
functions (mod)[" llvm.trap" ]
335
336
else
336
- LLVM. Function (mod, " llvm.trap" , LLVM . FunctionType (LLVM . VoidType (ctx)) )
337
+ LLVM. Function (mod, " llvm.trap" , trap_ft )
337
338
end
338
- call! (builder, trap)
339
+ call! (builder, trap_ft, trap)
339
340
end
340
341
341
342
435
436
# https://reviews.llvm.org/D79744
436
437
function lower_byval (@nospecialize (job:: CompilerJob ), mod:: LLVM.Module , f:: LLVM.Function )
437
438
ctx = context (mod)
438
- ft = eltype ( llvmtype (f) )
439
- @compiler_assert LLVM . return_type (ft) == LLVM. VoidType (ctx) job
439
+ ft = function_type (f )
440
+ @compiler_assert return_type (ft) == LLVM. VoidType (ctx) job
440
441
@timeit_debug to " lower byval" begin
441
442
442
443
# find the byval parameters
@@ -500,7 +501,7 @@ function lower_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.
500
501
push! (new_types, param)
501
502
end
502
503
end
503
- new_ft = LLVM. FunctionType (LLVM . return_type (ft), new_types)
504
+ new_ft = LLVM. FunctionType (return_type (ft), new_types)
504
505
new_f = LLVM. Function (mod, " " , new_ft)
505
506
linkage! (new_f, linkage (f))
506
507
for (arg, new_arg) in zip (parameters (f), parameters (new_f))
@@ -509,7 +510,7 @@ function lower_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.
509
510
510
511
# emit IR performing the "conversions"
511
512
new_args = LLVM. Value[]
512
- @dispose builder= Builder (ctx) begin
513
+ @dispose builder= IRBuilder (ctx) begin
513
514
entry = BasicBlock (new_f, " conversion" ; ctx)
514
515
position! (builder, entry)
515
516
@@ -591,6 +592,7 @@ function add_kernel_state!(mod::LLVM.Module)
591
592
# intrinsic returning an opaque pointer to the kernel state.
592
593
# this is both for extern uses, and to make this transformation a two-step process.
593
594
state_intr = kernel_state_intr (mod, T_state)
595
+ state_intr_ft = LLVM. FunctionType (T_state)
594
596
595
597
kernels = []
596
598
kernels_md = metadata (mod)[" julia.kernel" ]
@@ -636,12 +638,12 @@ function add_kernel_state!(mod::LLVM.Module)
636
638
workmap = Dict {LLVM.Function, LLVM.Function} ()
637
639
for f in worklist
638
640
fn = LLVM. name (f)
639
- ft = eltype ( llvmtype (f) )
641
+ ft = function_type (f )
640
642
LLVM. name! (f, fn * " .stateless" )
641
643
642
644
# create a new function
643
645
new_param_types = [T_state, parameters (ft)... ]
644
- new_ft = LLVM. FunctionType (LLVM . return_type (ft), new_param_types)
646
+ new_ft = LLVM. FunctionType (return_type (ft), new_param_types)
645
647
new_f = LLVM. Function (mod, fn, new_ft)
646
648
LLVM. name! (parameters (new_f)[1 ], " state" )
647
649
linkage! (new_f, linkage (f))
@@ -671,15 +673,15 @@ function add_kernel_state!(mod::LLVM.Module)
671
673
#
672
674
# XXX : ptrtoint/inttoptr pairs can also lose the state argument...
673
675
# is all this even sound?
674
- typ = llvmtype (val):: LLVM.PointerType
676
+ typ = value_type (val):: LLVM.PointerType
675
677
ft = eltype (typ):: LLVM.FunctionType
676
- new_ft = LLVM. FunctionType (LLVM . return_type (ft), [T_state, parameters (ft)... ])
678
+ new_ft = LLVM. FunctionType (return_type (ft), [T_state, parameters (ft)... ])
677
679
return const_bitcast (workmap[target], LLVM. PointerType (new_ft, addrspace (typ)))
678
680
end
679
681
elseif opcode (val) == LLVM. API. LLVMPtrToInt
680
682
target = operands (val)[1 ]
681
683
if target isa LLVM. Function && haskey (workmap, target)
682
- return const_ptrtoint (workmap[target], llvmtype (val))
684
+ return const_ptrtoint (workmap[target], value_type (val))
683
685
end
684
686
end
685
687
end
@@ -720,9 +722,9 @@ function add_kernel_state!(mod::LLVM.Module)
720
722
end
721
723
722
724
# update uses of the new function, modifying call sites to include the kernel state
723
- function rewrite_uses! (f)
725
+ function rewrite_uses! (f, ft )
724
726
# update uses
725
- @dispose builder= Builder (ctx) begin
727
+ @dispose builder= IRBuilder (ctx) begin
726
728
for use in uses (f)
727
729
val = user (use)
728
730
if val isa LLVM. CallBase && called_value (val) == f
@@ -739,9 +741,9 @@ function add_kernel_state!(mod::LLVM.Module)
739
741
740
742
# forward the state argument
741
743
position! (builder, val)
742
- state = call! (builder, state_intr, Value[], " state" )
744
+ state = call! (builder, state_intr_ft, state_intr, Value[], " state" )
743
745
new_val = if val isa LLVM. CallInst
744
- call! (builder, f, [state, arguments (val)... ], operand_bundles (val))
746
+ call! (builder, ft, f, [state, arguments (val)... ], operand_bundles (val))
745
747
else
746
748
# TODO : invoke and callbr
747
749
error (" Rewrite of $(typeof (val)) -based calls is not implemented: $val " )
@@ -757,15 +759,16 @@ function add_kernel_state!(mod::LLVM.Module)
757
759
elseif val isa LLVM. StoreInst
758
760
# the function is being stored, which again we'll permit like before.
759
761
elseif val isa ConstantExpr
760
- rewrite_uses! (val)
762
+ rewrite_uses! (val, ft )
761
763
else
762
764
error (" Cannot rewrite $(typeof (val)) use of function: $val " )
763
765
end
764
766
end
765
767
end
766
768
end
767
769
for f in values (workmap)
768
- rewrite_uses! (f)
770
+ ft = function_type (f)
771
+ rewrite_uses! (f, ft)
769
772
end
770
773
771
774
return true
@@ -791,7 +794,7 @@ function lower_kernel_state!(fun::LLVM.Function)
791
794
state_intr = functions (mod)[" julia.gpu.state_getter" ]
792
795
state_arg = nothing # only look-up when needed
793
796
794
- @dispose builder= Builder (ctx) begin
797
+ @dispose builder= IRBuilder (ctx) begin
795
798
for use in uses (state_intr)
796
799
inst = user (use)
797
800
@assert inst isa LLVM. CallInst
@@ -807,7 +810,7 @@ function lower_kernel_state!(fun::LLVM.Function)
807
810
# the function, but only when this function needs the state!
808
811
state_arg = parameters (fun)[1 ]
809
812
T_state = convert (LLVMType, state; ctx)
810
- @assert llvmtype (state_arg) == T_state
813
+ @assert value_type (state_arg) == T_state
811
814
end
812
815
813
816
replace_uses! (inst, state_arg)
@@ -865,13 +868,14 @@ function kernel_state_value(state)
865
868
866
869
# get intrinsic
867
870
state_intr = kernel_state_intr (mod, T_state)
871
+ state_intr_ft = function_type (state_intr)
868
872
869
873
# generate IR
870
- @dispose builder= Builder (ctx) begin
874
+ @dispose builder= IRBuilder (ctx) begin
871
875
entry = BasicBlock (llvm_f, " entry" ; ctx)
872
876
position! (builder, entry)
873
877
874
- val = call! (builder, state_intr, Value[], " state" )
878
+ val = call! (builder, state_intr_ft, state_intr, Value[], " state" )
875
879
876
880
ret! (builder, val)
877
881
end
0 commit comments