@@ -254,6 +254,11 @@ void jl_resolve_globals_in_ir(jl_array_t *stmts, jl_module_t *m, jl_svec_t *spar
254
254
}
255
255
}
256
256
257
+ jl_value_t * expr_arg1 (jl_value_t * expr ) {
258
+ jl_array_t * args = ((jl_expr_t * )expr )-> args ;
259
+ return jl_array_ptr_ref (args , 0 );
260
+ }
261
+
257
262
// copy a :lambda Expr into its CodeInfo representation,
258
263
// including popping of known meta nodes
259
264
static void jl_code_info_set_ir (jl_code_info_t * li , jl_expr_t * ir )
@@ -275,8 +280,17 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir)
275
280
jl_gc_wb (li , li -> code );
276
281
size_t n = jl_array_len (body );
277
282
jl_value_t * * bd = (jl_value_t * * )jl_array_ptr_data ((jl_array_t * )li -> code );
283
+ li -> ssaflags = jl_alloc_array_1d (jl_array_uint8_type , n );
284
+ jl_gc_wb (li , li -> ssaflags );
285
+ int inbounds_depth = 0 ; // number of stacked inbounds
286
+ // isempty(inline_flags): no user annotation
287
+ // last(inline_flags) == 1: inline region
288
+ // last(inline_flags) == 0: noinline region
289
+ arraylist_t * inline_flags = arraylist_new ((arraylist_t * )malloc_s (sizeof (arraylist_t )), 0 );
278
290
for (j = 0 ; j < n ; j ++ ) {
279
291
jl_value_t * st = bd [j ];
292
+ int is_flag_stmt = 0 ;
293
+ // check :meta expression
280
294
if (jl_is_expr (st ) && ((jl_expr_t * )st )-> head == meta_sym ) {
281
295
size_t k , ins = 0 , na = jl_expr_nargs (st );
282
296
jl_array_t * meta = ((jl_expr_t * )st )-> args ;
@@ -298,10 +312,57 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir)
298
312
else
299
313
jl_array_del_end (meta , na - ins );
300
314
}
315
+ // check other flag expressions
316
+ else if (jl_is_expr (st ) && ((jl_expr_t * )st )-> head == inbounds_sym ) {
317
+ is_flag_stmt = 1 ;
318
+ jl_value_t * arg1 = expr_arg1 (st );
319
+ if (arg1 == (jl_value_t * )jl_true ) // push
320
+ inbounds_depth += 1 ;
321
+ else if (arg1 == (jl_value_t * )jl_false ) // clear
322
+ inbounds_depth = 0 ;
323
+ else if (inbounds_depth > 0 ) // pop
324
+ inbounds_depth -= 1 ;
325
+ }
326
+ else if (jl_is_expr (st ) && ((jl_expr_t * )st )-> head == inline_sym ) {
327
+ is_flag_stmt = 1 ;
328
+ jl_value_t * arg1 = expr_arg1 (st );
329
+ if (arg1 == (jl_value_t * )jl_true ) // enter inline region
330
+ arraylist_push (inline_flags , (void * )1 );
331
+ else { // exit inline region
332
+ assert (arg1 == (jl_value_t * )jl_false );
333
+ arraylist_pop (inline_flags );
334
+ }
335
+ }
336
+ else if (jl_is_expr (st ) && ((jl_expr_t * )st )-> head == noinline_sym ) {
337
+ is_flag_stmt = 1 ;
338
+ jl_value_t * arg1 = expr_arg1 (st );
339
+ if (arg1 == (jl_value_t * )jl_true ) // enter noinline region
340
+ arraylist_push (inline_flags , (void * )0 );
341
+ else { // exit noinline region
342
+ assert (arg1 == (jl_value_t * )jl_false );
343
+ arraylist_pop (inline_flags );
344
+ }
345
+ }
301
346
else if (jl_is_expr (st ) && ((jl_expr_t * )st )-> head == return_sym ) {
302
347
jl_array_ptr_set (body , j , jl_new_struct (jl_returnnode_type , jl_exprarg (st , 0 )));
303
348
}
349
+
350
+ if (is_flag_stmt )
351
+ jl_array_uint8_set (li -> ssaflags , j , 0 );
352
+ else {
353
+ uint8_t flag = 0 ;
354
+ if (inbounds_depth > 0 )
355
+ flag |= 1 << 0 ;
356
+ if (inline_flags -> len > 0 ) {
357
+ void * inline_flag = inline_flags -> items [inline_flags -> len - 1 ];
358
+ flag |= 1 << (inline_flag ? 1 : 2 );
359
+ }
360
+ jl_array_uint8_set (li -> ssaflags , j , flag );
361
+ }
304
362
}
363
+ assert (inline_flags -> len == 0 ); // malformed otherwise
364
+ arraylist_free (inline_flags );
365
+ free (inline_flags );
305
366
jl_array_t * vinfo = (jl_array_t * )jl_exprarg (ir , 1 );
306
367
jl_array_t * vis = (jl_array_t * )jl_array_ptr_ref (vinfo , 0 );
307
368
size_t nslots = jl_array_len (vis );
@@ -314,7 +375,6 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir)
314
375
jl_gc_wb (li , li -> slotflags );
315
376
li -> ssavaluetypes = jl_box_long (nssavalue );
316
377
jl_gc_wb (li , li -> ssavaluetypes );
317
- li -> ssaflags = jl_alloc_array_1d (jl_array_uint8_type , 0 );
318
378
319
379
// Flags that need to be copied to slotflags
320
380
const uint8_t vinfo_mask = 8 | 16 | 32 | 64 ;
0 commit comments