@@ -127,33 +127,10 @@ function optimize!(code::CodeInfo, scope)
127
127
end
128
128
end
129
129
130
- # # Un-nest :call expressions (so that there will be only one :call per line)
131
- # This will allow us to re-use args-buffers rather than having to allocate new ones each time.
132
- old_code, old_codelocs = code. code, code. codelocs
133
- code. code = new_code = eltype (old_code)[]
134
- code. codelocs = new_codelocs = Int32[]
135
- ssainc = fill (1 , length (old_code))
136
- for (i, stmt) in enumerate (old_code)
137
- loc = old_codelocs[i]
138
- inner = extract_inner_call! (stmt, length (new_code)+ 1 )
139
- while inner != = nothing
140
- push! (new_code, inner)
141
- push! (new_codelocs, loc)
142
- ssainc[i] += 1
143
- inner = extract_inner_call! (stmt, length (new_code)+ 1 )
144
- end
145
- push! (new_code, stmt)
146
- push! (new_codelocs, loc)
147
- end
148
- # Fix all the SSAValues and GotoNodes
149
- ssalookup = cumsum (ssainc)
150
- renumber_ssa! (new_code, ssalookup)
151
- code. ssavaluetypes = length (new_code)
152
-
153
- # Replace :llvmcall and :foreigncall with compiled variants. See
130
+ # Replace :llvmcall and :foreigncall with compiled variants. See
154
131
# https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/13#issuecomment-464880123
155
- methodtables = Vector {Union{Compiled,TypeMapEntry}} (undef, length (code. code))
156
132
# @show code
133
+ foreigncalls_idx = Int[]
157
134
for (idx, stmt) in enumerate (code. code)
158
135
# Foregincalls can be rhs of assignments
159
136
if isexpr (stmt, :(= ))
@@ -168,7 +145,7 @@ function optimize!(code::CodeInfo, scope)
168
145
methname = Symbol (" llvmcall_" , ustr)
169
146
nargs = length (stmt. args)- 4
170
147
build_compiled_call! (stmt, methname, Base. llvmcall, stmt. args[2 : 4 ], code, idx, nargs, sparams)
171
- methodtables[idx] = Compiled ( )
148
+ push! (foreigncalls_idx, idx )
172
149
end
173
150
elseif isexpr (stmt, :foreigncall ) && scope isa Method
174
151
f = lookup_stmt (code. code, stmt. args[1 ])
@@ -193,8 +170,37 @@ function optimize!(code::CodeInfo, scope)
193
170
methname = Symbol (" ccall" , ' _' , f, ' _' , ustr)
194
171
nargs = stmt. args[5 ]
195
172
build_compiled_call! (stmt, methname, :ccall , stmt. args[1 : 3 ], code, idx, nargs, sparams)
196
- methodtables[idx] = Compiled ()
173
+ push! (foreigncalls_idx, idx)
174
+ end
175
+ end
176
+
177
+ # # Un-nest :call expressions (so that there will be only one :call per line)
178
+ # This will allow us to re-use args-buffers rather than having to allocate new ones each time.
179
+ old_code, old_codelocs = code. code, code. codelocs
180
+ code. code = new_code = eltype (old_code)[]
181
+ code. codelocs = new_codelocs = Int32[]
182
+ ssainc = fill (1 , length (old_code))
183
+ for (i, stmt) in enumerate (old_code)
184
+ loc = old_codelocs[i]
185
+ inner = extract_inner_call! (stmt, length (new_code)+ 1 )
186
+ while inner != = nothing
187
+ push! (new_code, inner)
188
+ push! (new_codelocs, loc)
189
+ ssainc[i] += 1
190
+ inner = extract_inner_call! (stmt, length (new_code)+ 1 )
197
191
end
192
+ push! (new_code, stmt)
193
+ push! (new_codelocs, loc)
194
+ end
195
+ # Fix all the SSAValues and GotoNodes
196
+ ssalookup = cumsum (ssainc)
197
+ renumber_ssa! (new_code, ssalookup)
198
+ code. ssavaluetypes = length (new_code)
199
+
200
+ # Insert the foreigncall wrappers at the updated idxs
201
+ methodtables = Vector {Union{Compiled,TypeMapEntry}} (undef, length (code. code))
202
+ for idx in foreigncalls_idx
203
+ methodtables[ssalookup[idx]] = Compiled ()
198
204
end
199
205
200
206
return code, methodtables
@@ -259,7 +265,7 @@ function build_compiled_call!(stmt, methname, fcall, typargs, code, idx, nargs,
259
265
RetType = parametric_type_to_expr (RetType)
260
266
wrapargs = copy (argnames)
261
267
for sparam in sparams
262
- push! (wrapargs, :(:: Type {$sparam} ))
268
+ push! (wrapargs, :(:: Val {$sparam} ))
263
269
end
264
270
if stmt. args[4 ] == :(:llvmcall )
265
271
def = :(
@@ -278,7 +284,7 @@ function build_compiled_call!(stmt, methname, fcall, typargs, code, idx, nargs,
278
284
deleteat! (stmt. args, 2 : length (stmt. args))
279
285
append! (stmt. args, args)
280
286
for i in 1 : length (sparams)
281
- push! (stmt. args, :($ ( Expr (:static_parameter , i))))
287
+ push! (stmt. args, :($ Val ( $ ( Expr (:static_parameter , i) ))))
282
288
end
283
289
return
284
290
end
0 commit comments