@@ -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 ();
@@ -6941,10 +6941,11 @@ static Function *gen_invoke_wrapper(jl_method_instance_t *lam, jl_value_t *jlret
6941
6941
return w;
6942
6942
}
6943
6943
6944
- 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)
6944
+ 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 )
6945
6945
{
6946
6946
jl_returninfo_t props = {};
6947
6947
SmallVector<Type*, 8 > fsig;
6948
+ SmallVector<std::string, 4 > argnames;
6948
6949
Type *rt = NULL ;
6949
6950
Type *srt = NULL ;
6950
6951
if (jlrettype == (jl_value_t *)jl_bottom_type) {
@@ -6962,6 +6963,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
6962
6963
props.cc = jl_returninfo_t ::Union;
6963
6964
Type *AT = ArrayType::get (getInt8Ty (ctx.builder .getContext ()), props.union_bytes );
6964
6965
fsig.push_back (AT->getPointerTo ());
6966
+ argnames.push_back (" union_bytes_return" );
6965
6967
Type *pair[] = { ctx.types ().T_prjlvalue , getInt8Ty (ctx.builder .getContext ()) };
6966
6968
rt = StructType::get (ctx.builder .getContext (), makeArrayRef (pair));
6967
6969
}
@@ -6986,6 +6988,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
6986
6988
// sret is always passed from alloca
6987
6989
assert (M);
6988
6990
fsig.push_back (rt->getPointerTo (M->getDataLayout ().getAllocaAddrSpace ()));
6991
+ argnames.push_back (" sret_return" );
6989
6992
srt = rt;
6990
6993
rt = getVoidTy (ctx.builder .getContext ());
6991
6994
}
@@ -7024,6 +7027,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
7024
7027
param.addAttribute (Attribute::NoUndef);
7025
7028
attrs.push_back (AttributeSet::get (ctx.builder .getContext (), param));
7026
7029
fsig.push_back (get_returnroots_type (ctx, props.return_roots )->getPointerTo (0 ));
7030
+ argnames.push_back (" return_roots" );
7027
7031
}
7028
7032
7029
7033
if (gcstack_arg){
@@ -7032,9 +7036,16 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
7032
7036
param.addAttribute (Attribute::NonNull);
7033
7037
attrs.push_back (AttributeSet::get (ctx.builder .getContext (), param));
7034
7038
fsig.push_back (PointerType::get (JuliaType::get_ppjlvalue_ty (ctx.builder .getContext ()), 0 ));
7039
+ argnames.push_back (" pgcstack_arg" );
7035
7040
}
7036
7041
7037
- for (size_t i = 0 ; i < jl_nparams (sig); i++) {
7042
+ if (arg_offset)
7043
+ *arg_offset = fsig.size ();
7044
+ size_t nparams = jl_nparams (sig);
7045
+ if (used_arguments)
7046
+ used_arguments->resize (nparams);
7047
+
7048
+ for (size_t i = 0 ; i < nparams; i++) {
7038
7049
jl_value_t *jt = jl_tparam (sig, i);
7039
7050
bool isboxed = false ;
7040
7051
Type *ty = NULL ;
@@ -7066,6 +7077,8 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
7066
7077
}
7067
7078
attrs.push_back (AttributeSet::get (ctx.builder .getContext (), param));
7068
7079
fsig.push_back (ty);
7080
+ if (used_arguments)
7081
+ used_arguments->set (i);
7069
7082
}
7070
7083
7071
7084
AttributeSet FnAttrs;
@@ -7095,8 +7108,14 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
7095
7108
else
7096
7109
fval = emit_bitcast (ctx, fval, ftype->getPointerTo ());
7097
7110
}
7098
- if (gcstack_arg && isa<Function>(fval))
7099
- cast<Function>(fval)->setCallingConv (CallingConv::Swift);
7111
+ if (auto F = dyn_cast<Function>(fval)) {
7112
+ if (gcstack_arg)
7113
+ F->setCallingConv (CallingConv::Swift);
7114
+ assert (F->arg_size () >= argnames.size ());
7115
+ for (size_t i = 0 ; i < argnames.size (); i++) {
7116
+ F->getArg (i)->setName (argnames[i]);
7117
+ }
7118
+ }
7100
7119
props.decl = FunctionCallee (ftype, fval);
7101
7120
props.attrs = attributes;
7102
7121
return props;
@@ -7322,11 +7341,49 @@ static jl_llvm_functions_t
7322
7341
Function *f = NULL ;
7323
7342
bool has_sret = false ;
7324
7343
if (specsig) { // assumes !va and !needsparams
7344
+ BitVector used_args;
7345
+ size_t args_begin;
7325
7346
returninfo = get_specsig_function (ctx, M, NULL , declarations.specFunctionObject , lam->specTypes ,
7326
- jlrettype, ctx.is_opaque_closure , JL_FEAT_TEST (ctx,gcstack_arg));
7347
+ jlrettype, ctx.is_opaque_closure , JL_FEAT_TEST (ctx,gcstack_arg), &used_args, &args_begin );
7327
7348
f = cast<Function>(returninfo.decl .getCallee ());
7328
7349
has_sret = (returninfo.cc == jl_returninfo_t ::SRet || returninfo.cc == jl_returninfo_t ::Union);
7329
7350
jl_init_function (f, ctx.emission_context .TargetTriple );
7351
+ if (ctx.emission_context .debug_level > 0 ) {
7352
+ auto arg_typename = [&](size_t i) JL_NOTSAFEPOINT {
7353
+ auto tp = jl_tparam (lam->specTypes , i);
7354
+ return jl_is_datatype (tp) ? jl_symbol_name (((jl_datatype_t *)tp)->name ->name ) : " <unknown type>" ;
7355
+ };
7356
+ size_t nreal = 0 ;
7357
+ for (size_t i = 0 ; i < std::min (nreq, static_cast <size_t >(used_args.size ())); i++) {
7358
+ jl_sym_t *argname = slot_symbol (ctx, i);
7359
+ if (argname == jl_unused_sym)
7360
+ continue ;
7361
+ if (used_args.test (i)) {
7362
+ auto &arg = *f->getArg (args_begin++);
7363
+ nreal++;
7364
+ auto name = jl_symbol_name (argname);
7365
+ if (!name[0 ]) {
7366
+ arg.setName (StringRef (" #" ) + Twine (nreal) + StringRef (" ::" ) + arg_typename (i));
7367
+ } else {
7368
+ arg.setName (name + StringRef (" ::" ) + arg_typename (i));
7369
+ }
7370
+ }
7371
+ }
7372
+ if (va && ctx.vaSlot != -1 ) {
7373
+ size_t vidx = 0 ;
7374
+ for (size_t i = nreq; i < used_args.size (); i++) {
7375
+ if (used_args.test (i)) {
7376
+ auto &arg = *f->getArg (args_begin++);
7377
+ auto type = arg_typename (i);
7378
+ const char *name = jl_symbol_name (slot_symbol (ctx, ctx.vaSlot ));
7379
+ if (!name[0 ])
7380
+ name = " ..." ;
7381
+ vidx++;
7382
+ arg.setName (name + StringRef (" [" ) + Twine (vidx) + StringRef (" ]::" ) + type);
7383
+ }
7384
+ }
7385
+ }
7386
+ }
7330
7387
7331
7388
// common pattern: see if all return statements are an argument in that
7332
7389
// case the apply-generic call can re-use the original box for the return
0 commit comments