Skip to content

Commit c5b8c71

Browse files
committed
Handle 1.11 GVs
1 parent 958bec7 commit c5b8c71

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/driver.jl

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,29 @@ end
162162
end
163163
end
164164

165+
function find_base_object(val)
166+
while true
167+
if val isa ConstantExpr && (opcode(val) == LLVM.API.LLVMIntToPtr ||
168+
opcode(val) == LLVM.API.LLVMBitCast ||
169+
opcode(val) == LLVM.API.LLVMAddrSpaceCast)
170+
val = first(operands(val))
171+
elseif val isa LLVM.IntToPtrInst || val isa LLVM.BitCastInst || val isa LLVM.AddrSpaceCastInst
172+
val = first(operands(val))
173+
elseif val isa LLVM.LoadInst
174+
# In 1.11+ we no longer embed integer constants directly.
175+
gv = first(operands(val))
176+
if gv isa LLVM.GlobalValue
177+
val = LLVM.initializer(gv)
178+
continue
179+
end
180+
break
181+
else
182+
break
183+
end
184+
end
185+
return val
186+
end
187+
165188
const __llvm_initialized = Ref(false)
166189

167190
@locked function emit_llvm(@nospecialize(job::CompilerJob);
@@ -190,19 +213,6 @@ const __llvm_initialized = Ref(false)
190213
# since those modules have been finalized themselves, and we don't want to re-finalize.
191214
entry = finish_module!(job, ir, entry)
192215

193-
function unwrap_constant(val)
194-
while val isa ConstantExpr
195-
if opcode(val) == LLVM.API.LLVMIntToPtr ||
196-
opcode(val) == LLVM.API.LLVMBitCast ||
197-
opcode(val) == LLVM.API.LLVMAddrSpaceCast
198-
val = first(operands(val))
199-
else
200-
break
201-
end
202-
end
203-
return val
204-
end
205-
206216
# deferred code generation
207217
has_deferred_jobs = !only_entry && toplevel && haskey(functions(ir), "deferred_codegen")
208218

@@ -216,8 +226,6 @@ const __llvm_initialized = Ref(false)
216226
changed = false
217227

218228
# find deferred compiler
219-
# TODO: recover this information earlier, from the Julia IR
220-
# We can do this now with gpuc.lookup
221229
worklist = Dict{CompilerJob, Vector{LLVM.CallInst}}()
222230
for use in uses(dyn_marker)
223231
# decode the call
@@ -292,8 +300,10 @@ const __llvm_initialized = Ref(false)
292300
for use in uses(dyn_marker)
293301
# decode the call
294302
call = user(use)::LLVM.CallInst
303+
dyn_mi_inst = find_base_object(operands(call)[1])
304+
@compiler_assert isa(dyn_mi_inst, LLVM.ConstantInt) job
295305
dyn_mi = Base.unsafe_pointer_to_objref(
296-
convert(Ptr{Cvoid}, convert(Int, unwrap_constant(operands(call)[1]))))
306+
convert(Ptr{Cvoid}, convert(Int, dyn_mi_inst)))
297307
push!(get!(worklist, dyn_mi, LLVM.CallInst[]), call)
298308
end
299309

0 commit comments

Comments
 (0)