162
162
end
163
163
end
164
164
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
+
165
188
const __llvm_initialized = Ref (false )
166
189
167
190
@locked function emit_llvm (@nospecialize (job:: CompilerJob );
@@ -190,19 +213,6 @@ const __llvm_initialized = Ref(false)
190
213
# since those modules have been finalized themselves, and we don't want to re-finalize.
191
214
entry = finish_module! (job, ir, entry)
192
215
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
-
206
216
# deferred code generation
207
217
has_deferred_jobs = ! only_entry && toplevel && haskey (functions (ir), " deferred_codegen" )
208
218
@@ -216,8 +226,6 @@ const __llvm_initialized = Ref(false)
216
226
changed = false
217
227
218
228
# find deferred compiler
219
- # TODO : recover this information earlier, from the Julia IR
220
- # We can do this now with gpuc.lookup
221
229
worklist = Dict {CompilerJob, Vector{LLVM.CallInst}} ()
222
230
for use in uses (dyn_marker)
223
231
# decode the call
@@ -292,8 +300,10 @@ const __llvm_initialized = Ref(false)
292
300
for use in uses (dyn_marker)
293
301
# decode the call
294
302
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
295
305
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 )))
297
307
push! (get! (worklist, dyn_mi, LLVM. CallInst[]), call)
298
308
end
299
309
0 commit comments