@@ -1736,7 +1736,7 @@ jl_aliasinfo_t jl_aliasinfo_t::fromTBAA(jl_codectx_t &ctx, MDNode *tbaa) {
1736
1736
}
1737
1737
1738
1738
static Type *julia_type_to_llvm (jl_codectx_t &ctx, jl_value_t *jt, bool *isboxed = NULL );
1739
- static jl_returninfo_t get_specsig_function (jl_codectx_t &ctx, Module *M, Value *fval, StringRef name, jl_value_t *sig, jl_value_t *jlrettype, bool is_opaque_closure, bool gcstack_arg);
1739
+ static jl_returninfo_t get_specsig_function (jl_codectx_t &ctx, Module *M, Value *fval, StringRef name, jl_value_t *sig, jl_value_t *jlrettype, bool is_opaque_closure, bool gcstack_arg, BitVector *used_arguments= nullptr , size_t *args_begin= nullptr );
1740
1740
static jl_cgval_t emit_expr (jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval = -1 );
1741
1741
static Value *global_binding_pointer (jl_codectx_t &ctx, jl_module_t *m, jl_sym_t *s,
1742
1742
jl_binding_t **pbnd, bool assign);
@@ -2363,17 +2363,17 @@ std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &conte
2363
2363
2364
2364
static void jl_name_jlfunc_args (jl_codegen_params_t ¶ms, Function *F) {
2365
2365
assert (F->arg_size () == 3 );
2366
- F->getArg (0 )->setName (" function" );
2367
- F->getArg (1 )->setName (" args" );
2368
- F->getArg (2 )->setName (" nargs" );
2366
+ F->getArg (0 )->setName (" function::Core.Function " );
2367
+ F->getArg (1 )->setName (" args::Any[] " );
2368
+ F->getArg (2 )->setName (" nargs::UInt32 " );
2369
2369
}
2370
2370
2371
2371
static void jl_name_jlfuncparams_args (jl_codegen_params_t ¶ms, Function *F) {
2372
2372
assert (F->arg_size () == 4 );
2373
- F->getArg (0 )->setName (" function" );
2374
- F->getArg (1 )->setName (" args" );
2375
- F->getArg (2 )->setName (" nargs" );
2376
- F->getArg (3 )->setName (" sparams" );
2373
+ F->getArg (0 )->setName (" function::Core.Function " );
2374
+ F->getArg (1 )->setName (" args::Any[] " );
2375
+ F->getArg (2 )->setName (" nargs::UInt32 " );
2376
+ F->getArg (3 )->setName (" sparams::Any " );
2377
2377
}
2378
2378
2379
2379
static void jl_init_function (Function *F, const Triple &TT)
@@ -4359,7 +4359,7 @@ static jl_cgval_t emit_call_specfun_boxed(jl_codectx_t &ctx, jl_value_t *jlretty
4359
4359
}
4360
4360
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA (ctx, ctx.tbaa ().tbaa_const );
4361
4361
theFptr = ai.decorateInst (ctx.builder .CreateAlignedLoad (pfunc, GV, Align (sizeof (void *))));
4362
- setName (ctx.emission_context , theFptr, namep );
4362
+ setName (ctx.emission_context , theFptr, specFunctionObject );
4363
4363
}
4364
4364
else {
4365
4365
theFptr = jl_Module->getOrInsertFunction (specFunctionObject, ctx.types ().T_jlfunc ).getCallee ();
@@ -6935,10 +6935,11 @@ static Function *gen_invoke_wrapper(jl_method_instance_t *lam, jl_value_t *jlret
6935
6935
return w;
6936
6936
}
6937
6937
6938
- static jl_returninfo_t get_specsig_function (jl_codectx_t &ctx, Module *M, Value *fval, StringRef name, jl_value_t *sig, jl_value_t *jlrettype, bool is_opaque_closure, bool gcstack_arg)
6938
+ static jl_returninfo_t get_specsig_function (jl_codectx_t &ctx, Module *M, Value *fval, StringRef name, jl_value_t *sig, jl_value_t *jlrettype, bool is_opaque_closure, bool gcstack_arg, BitVector *used_arguments, size_t *arg_offset )
6939
6939
{
6940
6940
jl_returninfo_t props = {};
6941
6941
SmallVector<Type*, 8 > fsig;
6942
+ SmallVector<std::string, 4 > argnames;
6942
6943
Type *rt = NULL ;
6943
6944
Type *srt = NULL ;
6944
6945
if (jlrettype == (jl_value_t *)jl_bottom_type) {
@@ -6956,6 +6957,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
6956
6957
props.cc = jl_returninfo_t ::Union;
6957
6958
Type *AT = ArrayType::get (getInt8Ty (ctx.builder .getContext ()), props.union_bytes );
6958
6959
fsig.push_back (AT->getPointerTo ());
6960
+ argnames.push_back (" union_bytes_return" );
6959
6961
Type *pair[] = { ctx.types ().T_prjlvalue , getInt8Ty (ctx.builder .getContext ()) };
6960
6962
rt = StructType::get (ctx.builder .getContext (), makeArrayRef (pair));
6961
6963
}
@@ -6980,6 +6982,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
6980
6982
// sret is always passed from alloca
6981
6983
assert (M);
6982
6984
fsig.push_back (rt->getPointerTo (M->getDataLayout ().getAllocaAddrSpace ()));
6985
+ argnames.push_back (" sret_return" );
6983
6986
srt = rt;
6984
6987
rt = getVoidTy (ctx.builder .getContext ());
6985
6988
}
@@ -7018,6 +7021,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
7018
7021
param.addAttribute (Attribute::NoUndef);
7019
7022
attrs.push_back (AttributeSet::get (ctx.builder .getContext (), param));
7020
7023
fsig.push_back (get_returnroots_type (ctx, props.return_roots )->getPointerTo (0 ));
7024
+ argnames.push_back (" return_roots" );
7021
7025
}
7022
7026
7023
7027
if (gcstack_arg){
@@ -7026,9 +7030,16 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
7026
7030
param.addAttribute (Attribute::NonNull);
7027
7031
attrs.push_back (AttributeSet::get (ctx.builder .getContext (), param));
7028
7032
fsig.push_back (PointerType::get (JuliaType::get_ppjlvalue_ty (ctx.builder .getContext ()), 0 ));
7033
+ argnames.push_back (" pgcstack_arg" );
7029
7034
}
7030
7035
7031
- for (size_t i = 0 ; i < jl_nparams (sig); i++) {
7036
+ if (arg_offset)
7037
+ *arg_offset = fsig.size ();
7038
+ size_t nparams = jl_nparams (sig);
7039
+ if (used_arguments)
7040
+ used_arguments->resize (nparams);
7041
+
7042
+ for (size_t i = 0 ; i < nparams; i++) {
7032
7043
jl_value_t *jt = jl_tparam (sig, i);
7033
7044
bool isboxed = false ;
7034
7045
Type *ty = NULL ;
@@ -7060,6 +7071,8 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
7060
7071
}
7061
7072
attrs.push_back (AttributeSet::get (ctx.builder .getContext (), param));
7062
7073
fsig.push_back (ty);
7074
+ if (used_arguments)
7075
+ used_arguments->set (i);
7063
7076
}
7064
7077
7065
7078
AttributeSet FnAttrs;
@@ -7089,8 +7102,14 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
7089
7102
else
7090
7103
fval = emit_bitcast (ctx, fval, ftype->getPointerTo ());
7091
7104
}
7092
- if (gcstack_arg && isa<Function>(fval))
7093
- cast<Function>(fval)->setCallingConv (CallingConv::Swift);
7105
+ if (auto F = dyn_cast<Function>(fval)) {
7106
+ if (gcstack_arg)
7107
+ F->setCallingConv (CallingConv::Swift);
7108
+ assert (F->arg_size () >= argnames.size ());
7109
+ for (size_t i = 0 ; i < argnames.size (); i++) {
7110
+ F->getArg (i)->setName (argnames[i]);
7111
+ }
7112
+ }
7094
7113
props.decl = FunctionCallee (ftype, fval);
7095
7114
props.attrs = attributes;
7096
7115
return props;
@@ -7316,11 +7335,49 @@ static jl_llvm_functions_t
7316
7335
Function *f = NULL ;
7317
7336
bool has_sret = false ;
7318
7337
if (specsig) { // assumes !va and !needsparams
7338
+ BitVector used_args;
7339
+ size_t args_begin;
7319
7340
returninfo = get_specsig_function (ctx, M, NULL , declarations.specFunctionObject , lam->specTypes ,
7320
- jlrettype, ctx.is_opaque_closure , JL_FEAT_TEST (ctx,gcstack_arg));
7341
+ jlrettype, ctx.is_opaque_closure , JL_FEAT_TEST (ctx,gcstack_arg), &used_args, &args_begin );
7321
7342
f = cast<Function>(returninfo.decl .getCallee ());
7322
7343
has_sret = (returninfo.cc == jl_returninfo_t ::SRet || returninfo.cc == jl_returninfo_t ::Union);
7323
7344
jl_init_function (f, ctx.emission_context .TargetTriple );
7345
+ if (ctx.emission_context .debug_level > 0 ) {
7346
+ auto arg_typename = [&](size_t i) JL_NOTSAFEPOINT {
7347
+ auto tp = jl_tparam (lam->specTypes , i);
7348
+ return jl_is_datatype (tp) ? jl_symbol_name (((jl_datatype_t *)tp)->name ->name ) : " <unknown type>" ;
7349
+ };
7350
+ size_t nreal = 0 ;
7351
+ for (size_t i = 0 ; i < std::min (nreq, static_cast <size_t >(used_args.size ())); i++) {
7352
+ jl_sym_t *argname = slot_symbol (ctx, i);
7353
+ if (argname == jl_unused_sym)
7354
+ continue ;
7355
+ if (used_args.test (i)) {
7356
+ auto &arg = *f->getArg (args_begin++);
7357
+ nreal++;
7358
+ auto name = jl_symbol_name (argname);
7359
+ if (!name[0 ]) {
7360
+ arg.setName (StringRef (" #" ) + Twine (nreal) + StringRef (" ::" ) + arg_typename (i));
7361
+ } else {
7362
+ arg.setName (name + StringRef (" ::" ) + arg_typename (i));
7363
+ }
7364
+ }
7365
+ }
7366
+ if (va && ctx.vaSlot != -1 ) {
7367
+ size_t vidx = 0 ;
7368
+ for (size_t i = nreq; i < used_args.size (); i++) {
7369
+ if (used_args.test (i)) {
7370
+ auto &arg = *f->getArg (args_begin++);
7371
+ auto type = arg_typename (i);
7372
+ const char *name = jl_symbol_name (slot_symbol (ctx, ctx.vaSlot ));
7373
+ if (!name[0 ])
7374
+ name = " ..." ;
7375
+ vidx++;
7376
+ arg.setName (name + StringRef (" [" ) + Twine (vidx) + StringRef (" ]::" ) + type);
7377
+ }
7378
+ }
7379
+ }
7380
+ }
7324
7381
7325
7382
// common pattern: see if all return statements are an argument in that
7326
7383
// case the apply-generic call can re-use the original box for the return
0 commit comments