Skip to content

Commit 1f1790f

Browse files
committed
Save a reference to the function name instead.
Works around an LLVM limitation.
1 parent 7fa1f9e commit 1f1790f

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/driver.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ const __llvm_initialized = Ref(false)
321321
if deferred_codegen
322322
# IDEA: save other parts of the CompileJob (so that we can reconstruct it
323323
# instead of setting it globally, which is incompatible with threading)?
324-
push!(metadata(ir)["julia.entry"], MDNode([entry]; ctx))
324+
# XXX: we want to save the actual function here, but due to our passes rewriting
325+
# functions, and the inability to RAUW values with a different type, that
326+
# metadata gets lost. So instead we save the function name. See also:
327+
# https://discourse.llvm.org/t/replacing-module-metadata-uses-of-function/62431
328+
push!(metadata(ir)["julia.entry"], MDNode([MDString(LLVM.name(entry); ctx)]; ctx))
325329
end
326330

327331
if optimize

src/irgen.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,8 @@ function add_kernel_state!(mod::LLVM.Module)
552552
state_intr = kernel_state_intr(mod, T_state)
553553

554554
entry_md = operands(metadata(mod)["julia.entry"])[1]
555-
entry = Value(operands(entry_md)[1]; ctx)
556-
# XXX: this metadata will be invalid after the replacement here (it'll be null).
557-
# how do we replace Metadata uses? Normally RAUW, but it asserts type equality
555+
entry_fn = string(operands(entry_md)[1])
556+
entry = functions(mod)[entry_fn]
558557

559558
# determine which functions need a kernel state argument
560559
#

src/ptx.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ function finish_ir!(@nospecialize(job::CompilerJob{PTXCompilerTarget}),
199199
# add metadata annotations for the assembler to the module
200200

201201
# NOTE: we do this here, rather than in finish_module!, because otherwise
202-
# the metadata is lost when functions are cloned.
203-
# XXX: why does this happen? shouldn't cloning preserve metadata?
202+
# the metadata is lost when functions are cloned. See also:
203+
# https://discourse.llvm.org/t/replacing-module-metadata-uses-of-function/62431
204204

205205
# property annotations
206206
annotations = Metadata[entry]

0 commit comments

Comments
 (0)