@@ -1736,7 +1736,7 @@ jl_aliasinfo_t jl_aliasinfo_t::fromTBAA(jl_codectx_t &ctx, MDNode *tbaa) {
17361736}
17371737
17381738static 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 );
17401740static jl_cgval_t emit_expr (jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval = -1 );
17411741static Value *global_binding_pointer (jl_codectx_t &ctx, jl_module_t *m, jl_sym_t *s,
17421742 jl_binding_t **pbnd, bool assign);
@@ -2363,17 +2363,17 @@ std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &conte
23632363
23642364static void jl_name_jlfunc_args (jl_codegen_params_t ¶ms, Function *F) {
23652365 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 " );
23692369}
23702370
23712371static void jl_name_jlfuncparams_args (jl_codegen_params_t ¶ms, Function *F) {
23722372 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 " );
23772377}
23782378
23792379static 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
43594359 }
43604360 jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA (ctx, ctx.tbaa ().tbaa_const );
43614361 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 );
43634363 }
43644364 else {
43654365 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
69416941 return w;
69426942}
69436943
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 )
69456945{
69466946 jl_returninfo_t props = {};
69476947 SmallVector<Type*, 8 > fsig;
6948+ SmallVector<std::string, 4 > argnames;
69486949 Type *rt = NULL ;
69496950 Type *srt = NULL ;
69506951 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
69626963 props.cc = jl_returninfo_t ::Union;
69636964 Type *AT = ArrayType::get (getInt8Ty (ctx.builder .getContext ()), props.union_bytes );
69646965 fsig.push_back (AT->getPointerTo ());
6966+ argnames.push_back (" union_bytes_return" );
69656967 Type *pair[] = { ctx.types ().T_prjlvalue , getInt8Ty (ctx.builder .getContext ()) };
69666968 rt = StructType::get (ctx.builder .getContext (), makeArrayRef (pair));
69676969 }
@@ -6986,6 +6988,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
69866988 // sret is always passed from alloca
69876989 assert (M);
69886990 fsig.push_back (rt->getPointerTo (M->getDataLayout ().getAllocaAddrSpace ()));
6991+ argnames.push_back (" sret_return" );
69896992 srt = rt;
69906993 rt = getVoidTy (ctx.builder .getContext ());
69916994 }
@@ -7024,6 +7027,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
70247027 param.addAttribute (Attribute::NoUndef);
70257028 attrs.push_back (AttributeSet::get (ctx.builder .getContext (), param));
70267029 fsig.push_back (get_returnroots_type (ctx, props.return_roots )->getPointerTo (0 ));
7030+ argnames.push_back (" return_roots" );
70277031 }
70287032
70297033 if (gcstack_arg){
@@ -7032,9 +7036,16 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
70327036 param.addAttribute (Attribute::NonNull);
70337037 attrs.push_back (AttributeSet::get (ctx.builder .getContext (), param));
70347038 fsig.push_back (PointerType::get (JuliaType::get_ppjlvalue_ty (ctx.builder .getContext ()), 0 ));
7039+ argnames.push_back (" pgcstack_arg" );
70357040 }
70367041
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++) {
70387049 jl_value_t *jt = jl_tparam (sig, i);
70397050 bool isboxed = false ;
70407051 Type *ty = NULL ;
@@ -7066,6 +7077,8 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
70667077 }
70677078 attrs.push_back (AttributeSet::get (ctx.builder .getContext (), param));
70687079 fsig.push_back (ty);
7080+ if (used_arguments)
7081+ used_arguments->set (i);
70697082 }
70707083
70717084 AttributeSet FnAttrs;
@@ -7095,8 +7108,14 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
70957108 else
70967109 fval = emit_bitcast (ctx, fval, ftype->getPointerTo ());
70977110 }
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+ }
71007119 props.decl = FunctionCallee (ftype, fval);
71017120 props.attrs = attributes;
71027121 return props;
@@ -7322,11 +7341,49 @@ static jl_llvm_functions_t
73227341 Function *f = NULL ;
73237342 bool has_sret = false ;
73247343 if (specsig) { // assumes !va and !needsparams
7344+ BitVector used_args;
7345+ size_t args_begin;
73257346 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 );
73277348 f = cast<Function>(returninfo.decl .getCallee ());
73287349 has_sret = (returninfo.cc == jl_returninfo_t ::SRet || returninfo.cc == jl_returninfo_t ::Union);
73297350 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+ }
73307387
73317388 // common pattern: see if all return statements are an argument in that
73327389 // case the apply-generic call can re-use the original box for the return
0 commit comments