@@ -247,7 +247,7 @@ static Function *to_function(jl_lambda_info_t *li, bool cstyle)
247
247
assert (f != NULL );
248
248
nested_compile = last_n_c;
249
249
// f->dump();
250
- verifyFunction (*f);
250
+ // verifyFunction(*f);
251
251
FPM->run (*f);
252
252
// n_compile++;
253
253
// print out the function's LLVM code
@@ -2025,23 +2025,44 @@ static Value *emit_expr(jl_value_t *expr, jl_codectx_t *ctx, bool isboxed,
2025
2025
}
2026
2026
return mark_julia_type (strct,ty);
2027
2027
}
2028
+ Value *f1 = NULL ;
2029
+ size_t j = 0 ;
2030
+ int fieldStart = ctx->argDepth ;
2031
+ if (nf > 0 && sty->fields [0 ].isptr && nargs>1 ) {
2032
+ // emit first field before allocating struct to save
2033
+ // a couple store instructions. avoids initializing
2034
+ // the first field to NULL, and sometimes the GC root
2035
+ // for the new struct.
2036
+ f1 = boxed (emit_expr (args[1 ],ctx));
2037
+ j++;
2038
+ if (!jl_is_symbol (args[1 ]) && !jl_is_symbolnode (args[1 ]))
2039
+ make_gcroot (f1, ctx);
2040
+ }
2028
2041
Value *strct =
2029
2042
builder.CreateCall (jlallocobj_func,
2030
2043
ConstantInt::get (T_size,
2031
2044
sizeof (void *)+sty->size ));
2032
2045
builder.CreateStore (literal_pointer_val ((jl_value_t *)ty),
2033
2046
emit_nthptr_addr (strct, (size_t )0 ));
2034
- for (size_t i=0 ; i < nf; i++) {
2047
+ if (f1) {
2048
+ emit_setfield (sty, strct, 0 , f1, ctx, false );
2049
+ ctx->argDepth = fieldStart;
2050
+ if (nf > 1 )
2051
+ make_gcroot (strct, ctx);
2052
+ }
2053
+ else if (nf > 0 ) {
2054
+ make_gcroot (strct, ctx);
2055
+ }
2056
+ for (size_t i=j; i < nf; i++) {
2035
2057
if (sty->fields [i].isptr ) {
2036
2058
emit_setfield (sty, strct, i, V_null, ctx, false );
2037
2059
}
2038
2060
}
2039
- make_gcroot (strct, ctx);
2040
- for (size_t i=1 ; i < nargs; i++) {
2061
+ for (size_t i=j+1 ; i < nargs; i++) {
2041
2062
emit_setfield (sty, strct, i-1 , emit_expr (args[i],ctx), ctx,
2042
2063
false );
2043
2064
}
2044
- ctx->argDepth -- ;
2065
+ ctx->argDepth = fieldStart ;
2045
2066
return strct;
2046
2067
}
2047
2068
else {
0 commit comments