Skip to content

Commit 27b82ba

Browse files
committed
Store the actual function in metadata, not just its name.
1 parent 4b23662 commit 27b82ba

File tree

6 files changed

+11
-17
lines changed

6 files changed

+11
-17
lines changed

Manifest.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ version = "1.4.1"
3939

4040
[[LLVM]]
4141
deps = ["CEnum", "LLVMExtra_jll", "Libdl", "Printf", "Unicode"]
42-
git-tree-sha1 = "d7f3db3b5f564016b5dfcc71a20506f8796f403a"
42+
git-tree-sha1 = "dd58421009014ff1ffacaa0db2a9a392114d75ee"
4343
uuid = "929cbde3-209d-540e-8aea-75f648917ca0"
44-
version = "4.10.0"
44+
version = "4.11.0"
4545

4646
[[LLVMExtra_jll]]
4747
deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg", "TOML"]
48-
git-tree-sha1 = "00d23b26d194507028b9a1c2728a691ab9914262"
48+
git-tree-sha1 = "771bfe376249626d3ca12bcd58ba243d3f961576"
4949
uuid = "dad2f222-ce93-54a1-a47d-0025e8a3acab"
50-
version = "0.0.15+0"
50+
version = "0.0.16+0"
5151

5252
[[LazyArtifacts]]
5353
deps = ["Artifacts", "Pkg"]

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1414

1515
[compat]
1616
ExprTools = "0.1"
17-
LLVM = "4.10"
17+
LLVM = "4.11"
1818
TimerOutputs = "0.5"
1919
julia = "1.6"

src/driver.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,9 @@ const __llvm_initialized = Ref(false)
318318
@timeit_debug to "IR post-processing" begin
319319
# mark the kernel entry-point functions (optimization may need it)
320320
if job.source.kernel
321-
# XXX: we want to save the actual function here, but due to our passes rewriting
322-
# functions, and the inability to RAUW values with a different type, that
323-
# metadata gets lost. So instead we save the function name. See also:
324-
# https://discourse.llvm.org/t/replacing-module-metadata-uses-of-function/62431
325-
push!(metadata(ir)["julia.kernel"], MDNode([MDString(LLVM.name(entry); ctx)]; ctx))
321+
push!(metadata(ir)["julia.kernel"], MDNode([entry]; ctx))
326322

327-
# IDEA: save all jobs, not only top-level kernels, and save other attributes
323+
# IDEA: save all jobs, not only kernels, and save other attributes
328324
# so that we can reconstruct the CompileJob instead of setting it globally
329325
end
330326

src/irgen.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ function lower_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.
510510
# NOTE: if we ever have legitimate uses of the old function, create a shim instead
511511
fn = LLVM.name(f)
512512
@assert isempty(uses(f))
513+
replace_metadata_uses!(f, new_f)
513514
unsafe_delete!(mod, f)
514515
LLVM.name!(new_f, fn)
515516

@@ -554,8 +555,7 @@ function add_kernel_state!(mod::LLVM.Module)
554555
kernels = []
555556
kernels_md = metadata(mod)["julia.kernel"]
556557
for kernel_md in operands(kernels_md)
557-
kernel_fn = string(operands(kernel_md)[1])
558-
push!(kernels, functions(mod)[kernel_fn])
558+
push!(kernels, Value(operands(kernel_md)[1]; ctx))
559559
end
560560

561561
# determine which functions need a kernel state argument
@@ -675,6 +675,7 @@ function add_kernel_state!(mod::LLVM.Module)
675675
error("old function still has uses")
676676
end
677677
end
678+
replace_metadata_uses!(f, workmap[f])
678679
unsafe_delete!(mod, f)
679680
end
680681

src/ptx.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ function finish_ir!(@nospecialize(job::CompilerJob{PTXCompilerTarget}),
198198
if job.source.kernel
199199
# add metadata annotations for the assembler to the module
200200

201-
# NOTE: we do this here, rather than in finish_module!, because otherwise
202-
# the metadata is lost when functions are cloned. See also:
203-
# https://discourse.llvm.org/t/replacing-module-metadata-uses-of-function/62431
204-
205201
# property annotations
206202
annotations = Metadata[entry]
207203

src/spirv.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ function wrap_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.F
317317
# NOTE: if we ever have legitimate uses of the old function, create a shim instead
318318
fn = LLVM.name(f)
319319
@assert isempty(uses(f))
320+
replace_metadata_uses!(f, new_f)
320321
unsafe_delete!(mod, f)
321322
LLVM.name!(new_f, fn)
322323

0 commit comments

Comments
 (0)