@@ -1048,30 +1048,64 @@ static const auto jlunlockfield_func = new JuliaFunction<>{
10481048};
10491049static const auto jlenter_func = new JuliaFunction<>{
10501050 XSTR (jl_enter_handler),
1051- [](LLVMContext &C) { return FunctionType::get (getVoidTy (C),
1052- {getInt8PtrTy (C)}, false ); },
1051+ [](LLVMContext &C) {
1052+ auto T_pjlvalue = JuliaType::get_pjlvalue_ty (C);
1053+ return FunctionType::get (getVoidTy (C),
1054+ {T_pjlvalue, getInt8PtrTy (C)}, false ); },
10531055 nullptr ,
10541056};
10551057static const auto jl_current_exception_func = new JuliaFunction<>{
10561058 XSTR (jl_current_exception),
1057- [](LLVMContext &C) { return FunctionType::get (JuliaType::get_prjlvalue_ty (C), false ); },
1059+ [](LLVMContext &C) { return FunctionType::get (JuliaType::get_prjlvalue_ty (C), { JuliaType::get_pjlvalue_ty (C)}, false ); },
10581060 nullptr ,
10591061};
10601062static const auto jlleave_func = new JuliaFunction<>{
10611063 XSTR (jl_pop_handler),
1062- [](LLVMContext &C) { return FunctionType::get (getVoidTy (C),
1063- {getInt32Ty (C)}, false ); },
1064- nullptr ,
1064+ [](LLVMContext &C) {
1065+ auto T_pjlvalue = JuliaType::get_pjlvalue_ty (C);
1066+ return FunctionType::get (getVoidTy (C),
1067+ {T_pjlvalue, getInt32Ty (C)}, false ); },
1068+ [](LLVMContext &C) {
1069+ auto FnAttrs = AttrBuilder (C);
1070+ FnAttrs.addAttribute (Attribute::WillReturn);
1071+ FnAttrs.addAttribute (Attribute::NoUnwind);
1072+ auto RetAttrs = AttrBuilder (C);
1073+ return AttributeList::get (C,
1074+ AttributeSet::get (C, FnAttrs),
1075+ AttributeSet (),
1076+ None);
1077+ },
1078+ };
1079+ static const auto jlleave_noexcept_func = new JuliaFunction<>{
1080+ XSTR (jl_pop_handler_noexcept),
1081+ [](LLVMContext &C) {
1082+ auto T_pjlvalue = JuliaType::get_pjlvalue_ty (C);
1083+ return FunctionType::get (getVoidTy (C),
1084+ {T_pjlvalue, getInt32Ty (C)}, false ); },
1085+ [](LLVMContext &C) {
1086+ auto FnAttrs = AttrBuilder (C);
1087+ FnAttrs.addAttribute (Attribute::WillReturn);
1088+ FnAttrs.addAttribute (Attribute::NoUnwind);
1089+ auto RetAttrs = AttrBuilder (C);
1090+ return AttributeList::get (C,
1091+ AttributeSet::get (C, FnAttrs),
1092+ AttributeSet (),
1093+ None);
1094+ },
10651095};
10661096static const auto jl_restore_excstack_func = new JuliaFunction<TypeFnContextAndSizeT>{
10671097 XSTR (jl_restore_excstack),
1068- [](LLVMContext &C, Type *T_size) { return FunctionType::get (getVoidTy (C),
1069- {T_size}, false ); },
1098+ [](LLVMContext &C, Type *T_size) {
1099+ auto T_pjlvalue = JuliaType::get_pjlvalue_ty (C);
1100+ return FunctionType::get (getVoidTy (C),
1101+ {T_pjlvalue, T_size}, false ); },
10701102 nullptr ,
10711103};
10721104static const auto jl_excstack_state_func = new JuliaFunction<TypeFnContextAndSizeT>{
10731105 XSTR (jl_excstack_state),
1074- [](LLVMContext &C, Type *T_size) { return FunctionType::get (T_size, false ); },
1106+ [](LLVMContext &C, Type *T_size) {
1107+ auto T_pjlvalue = JuliaType::get_pjlvalue_ty (C);
1108+ return FunctionType::get (T_size, {T_pjlvalue}, false ); },
10751109 nullptr ,
10761110};
10771111static const auto jlegalx_func = new JuliaFunction<TypeFnContextAndSizeT>{
@@ -1098,9 +1132,9 @@ static const auto jl_alloc_obj_func = new JuliaFunction<TypeFnContextAndSizeT>{
10981132 [](LLVMContext &C, Type *T_size) {
10991133 auto T_jlvalue = JuliaType::get_jlvalue_ty (C);
11001134 auto T_prjlvalue = PointerType::get (T_jlvalue, AddressSpace::Tracked);
1101- auto T_ppjlvalue = PointerType::get (PointerType::get ( T_jlvalue, 0 ) , 0 );
1135+ auto T_pjlvalue = PointerType::get (T_jlvalue, 0 );
11021136 return FunctionType::get (T_prjlvalue,
1103- {T_ppjlvalue , T_size, T_prjlvalue}, false );
1137+ {T_pjlvalue , T_size, T_prjlvalue}, false );
11041138 },
11051139 [](LLVMContext &C) {
11061140 auto FnAttrs = AttrBuilder (C);
@@ -1442,7 +1476,9 @@ static const auto gc_preserve_end_func = new JuliaFunction<> {
14421476};
14431477static const auto except_enter_func = new JuliaFunction<>{
14441478 " julia.except_enter" ,
1445- [](LLVMContext &C) { return FunctionType::get (getInt32Ty (C), false ); },
1479+ [](LLVMContext &C) {
1480+ auto T_pjlvalue = JuliaType::get_pjlvalue_ty (C);
1481+ return FunctionType::get (getInt32Ty (C), {T_pjlvalue}, false ); },
14461482 [](LLVMContext &C) { return AttributeList::get (C,
14471483 Attributes (C, {Attribute::ReturnsTwice}),
14481484 AttributeSet (),
@@ -5957,8 +5993,7 @@ static void emit_stmtpos(jl_codectx_t &ctx, jl_value_t *expr, int ssaval_result)
59575993 hand_n_leave += 1 ;
59585994 }
59595995 }
5960- ctx.builder .CreateCall (prepare_call (jlleave_func),
5961- ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), hand_n_leave));
5996+ ctx.builder .CreateCall (prepare_call (jlleave_noexcept_func), {get_current_task (ctx), ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), hand_n_leave)});
59625997 if (scope_to_restore) {
59635998 jl_aliasinfo_t scope_ai = jl_aliasinfo_t::fromTBAA (ctx, ctx.tbaa ().tbaa_gcframe );
59645999 scope_ai.decorateInst (
@@ -5968,7 +6003,7 @@ static void emit_stmtpos(jl_codectx_t &ctx, jl_value_t *expr, int ssaval_result)
59686003 else if (head == jl_pop_exception_sym) {
59696004 jl_cgval_t excstack_state = emit_expr (ctx, jl_exprarg (expr, 0 ));
59706005 assert (excstack_state.V && excstack_state.V ->getType () == ctx.types ().T_size );
5971- ctx.builder .CreateCall (prepare_call (jl_restore_excstack_func), excstack_state.V );
6006+ ctx.builder .CreateCall (prepare_call (jl_restore_excstack_func), { get_current_task (ctx), excstack_state.V } );
59726007 return ;
59736008 }
59746009 else {
@@ -6199,7 +6234,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaidx_
61996234 bnd = jl_get_binding_for_method_def (mod, (jl_sym_t *)mn);
62006235 }
62016236 JL_CATCH {
6202- jl_value_t *e = jl_current_exception ();
6237+ jl_value_t *e = jl_current_exception (jl_current_task );
62036238 // errors. boo. :(
62046239 JL_GC_PUSH1 (&e);
62056240 e = jl_as_global_root (e, 1 );
@@ -6375,7 +6410,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaidx_
63756410 else if (head == jl_exc_sym) {
63766411 assert (nargs == 0 );
63776412 return mark_julia_type (ctx,
6378- ctx.builder .CreateCall (prepare_call (jl_current_exception_func)),
6413+ ctx.builder .CreateCall (prepare_call (jl_current_exception_func), { get_current_task (ctx)} ),
63796414 true , jl_any_type);
63806415 }
63816416 else if (head == jl_copyast_sym) {
@@ -6479,9 +6514,14 @@ static void allocate_gc_frame(jl_codectx_t &ctx, BasicBlock *b0, bool or_new=fal
64796514 ctx.pgcstack ->setName (" pgcstack" );
64806515}
64816516
6517+ static Value *get_current_task (jl_codectx_t &ctx, Type *T)
6518+ {
6519+ return emit_bitcast (ctx, get_current_task_from_pgcstack (ctx.builder , ctx.types ().T_size , ctx.pgcstack ), T);
6520+ }
6521+
64826522static Value *get_current_task (jl_codectx_t &ctx)
64836523{
6484- return get_current_task_from_pgcstack (ctx. builder , ctx.types ().T_size , ctx. pgcstack );
6524+ return get_current_task (ctx, ctx.types ().T_pjlvalue );
64856525}
64866526
64876527// Get PTLS through current task.
@@ -6493,20 +6533,20 @@ static Value *get_current_ptls(jl_codectx_t &ctx)
64936533// Get the address of the world age of the current task
64946534static Value *get_last_age_field (jl_codectx_t &ctx)
64956535{
6496- Value *ct = get_current_task (ctx);
6536+ Value *ct = get_current_task (ctx, ctx. types (). T_size -> getPointerTo () );
64976537 return ctx.builder .CreateInBoundsGEP (
64986538 ctx.types ().T_size ,
6499- ctx. builder . CreateBitCast (ct, ctx. types (). T_size -> getPointerTo ()) ,
6539+ ct ,
65006540 ConstantInt::get (ctx.types ().T_size , offsetof (jl_task_t , world_age) / ctx.types ().sizeof_ptr ),
65016541 " world_age" );
65026542}
65036543
65046544static Value *get_scope_field (jl_codectx_t &ctx)
65056545{
6506- Value *ct = get_current_task (ctx);
6546+ Value *ct = get_current_task (ctx, ctx. types (). T_prjlvalue -> getPointerTo () );
65076547 return ctx.builder .CreateInBoundsGEP (
65086548 ctx.types ().T_prjlvalue ,
6509- ctx. builder . CreateBitCast (ct, ctx. types (). T_prjlvalue -> getPointerTo ()) ,
6549+ ct ,
65106550 ConstantInt::get (ctx.types ().T_size , offsetof (jl_task_t , scope) / ctx.types ().sizeof_ptr ),
65116551 " current_scope" );
65126552}
@@ -9119,12 +9159,12 @@ static jl_llvm_functions_t
91199159 if (lname) {
91209160 // Save exception stack depth at enter for use in pop_exception
91219161 Value *excstack_state =
9122- ctx.builder .CreateCall (prepare_call (jl_excstack_state_func));
9162+ ctx.builder .CreateCall (prepare_call (jl_excstack_state_func), { get_current_task (ctx)} );
91239163 assert (!ctx.ssavalue_assigned [cursor]);
91249164 ctx.SAvalues [cursor] = jl_cgval_t (excstack_state, (jl_value_t *)jl_ulong_type, NULL );
91259165 ctx.ssavalue_assigned [cursor] = true ;
91269166 // Actually enter the exception frame
9127- CallInst *sj = ctx.builder .CreateCall (prepare_call (except_enter_func));
9167+ CallInst *sj = ctx.builder .CreateCall (prepare_call (except_enter_func), { get_current_task (ctx)} );
91289168 // We need to mark this on the call site as well. See issue #6757
91299169 sj->setCanReturnTwice ();
91309170 Value *isz = ctx.builder .CreateICmpEQ (sj, ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), 0 ));
@@ -9137,8 +9177,7 @@ static jl_llvm_functions_t
91379177 ctx.builder .CreateCondBr (isz, tryblk, catchpop);
91389178 ctx.builder .SetInsertPoint (catchpop);
91399179 {
9140- ctx.builder .CreateCall (prepare_call (jlleave_func),
9141- ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), 1 ));
9180+ ctx.builder .CreateCall (prepare_call (jlleave_func), {get_current_task (ctx), ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), 1 )});
91429181 if (old_scope) {
91439182 scope_ai.decorateInst (
91449183 ctx.builder .CreateAlignedStore (old_scope, scope_ptr, ctx.types ().alignof_ptr ));
@@ -9504,7 +9543,7 @@ jl_llvm_functions_t jl_emit_code(
95049543 decls.functionObject = " " ;
95059544 decls.specFunctionObject = " " ;
95069545 jl_printf ((JL_STREAM*)STDERR_FILENO, " Internal error: encountered unexpected error during compilation of %s:\n " , mname.c_str ());
9507- jl_static_show ((JL_STREAM*)STDERR_FILENO, jl_current_exception ());
9546+ jl_static_show ((JL_STREAM*)STDERR_FILENO, jl_current_exception (jl_current_task ));
95089547 jl_printf ((JL_STREAM*)STDERR_FILENO, " \n " );
95099548 jlbacktrace (); // written to STDERR_FILENO
95109549#ifndef JL_NDEBUG
@@ -9816,6 +9855,7 @@ static void init_jit_functions(void)
98169855 add_named_global (jlgenericfunction_func, &jl_generic_function_def);
98179856 add_named_global (jlenter_func, &jl_enter_handler);
98189857 add_named_global (jl_current_exception_func, &jl_current_exception);
9858+ add_named_global (jlleave_noexcept_func, &jl_pop_handler_noexcept);
98199859 add_named_global (jlleave_func, &jl_pop_handler);
98209860 add_named_global (jl_restore_excstack_func, &jl_restore_excstack);
98219861 add_named_global (jl_excstack_state_func, &jl_excstack_state);
0 commit comments