@@ -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 (),
@@ -5961,8 +5997,7 @@ static void emit_stmtpos(jl_codectx_t &ctx, jl_value_t *expr, int ssaval_result)
59615997 hand_n_leave += 1 ;
59625998 }
59635999 }
5964- ctx.builder .CreateCall (prepare_call (jlleave_func),
5965- ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), hand_n_leave));
6000+ ctx.builder .CreateCall (prepare_call (jlleave_noexcept_func), {get_current_task (ctx), ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), hand_n_leave)});
59666001 if (scope_to_restore) {
59676002 jl_aliasinfo_t scope_ai = jl_aliasinfo_t::fromTBAA (ctx, ctx.tbaa ().tbaa_gcframe );
59686003 scope_ai.decorateInst (
@@ -5972,7 +6007,7 @@ static void emit_stmtpos(jl_codectx_t &ctx, jl_value_t *expr, int ssaval_result)
59726007 else if (head == jl_pop_exception_sym) {
59736008 jl_cgval_t excstack_state = emit_expr (ctx, jl_exprarg (expr, 0 ));
59746009 assert (excstack_state.V && excstack_state.V ->getType () == ctx.types ().T_size );
5975- ctx.builder .CreateCall (prepare_call (jl_restore_excstack_func), excstack_state.V );
6010+ ctx.builder .CreateCall (prepare_call (jl_restore_excstack_func), { get_current_task (ctx), excstack_state.V } );
59766011 return ;
59776012 }
59786013 else {
@@ -6203,7 +6238,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaidx_
62036238 bnd = jl_get_binding_for_method_def (mod, (jl_sym_t *)mn);
62046239 }
62056240 JL_CATCH {
6206- jl_value_t *e = jl_current_exception ();
6241+ jl_value_t *e = jl_current_exception (jl_current_task );
62076242 // errors. boo. :(
62086243 JL_GC_PUSH1 (&e);
62096244 e = jl_as_global_root (e, 1 );
@@ -6379,7 +6414,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaidx_
63796414 else if (head == jl_exc_sym) {
63806415 assert (nargs == 0 );
63816416 return mark_julia_type (ctx,
6382- ctx.builder .CreateCall (prepare_call (jl_current_exception_func)),
6417+ ctx.builder .CreateCall (prepare_call (jl_current_exception_func), { get_current_task (ctx)} ),
63836418 true , jl_any_type);
63846419 }
63856420 else if (head == jl_copyast_sym) {
@@ -6481,9 +6516,14 @@ static void allocate_gc_frame(jl_codectx_t &ctx, BasicBlock *b0, bool or_new=fal
64816516 ctx.pgcstack ->setName (" pgcstack" );
64826517}
64836518
6519+ static Value *get_current_task (jl_codectx_t &ctx, Type *T)
6520+ {
6521+ return emit_bitcast (ctx, get_current_task_from_pgcstack (ctx.builder , ctx.types ().T_size , ctx.pgcstack ), T);
6522+ }
6523+
64846524static Value *get_current_task (jl_codectx_t &ctx)
64856525{
6486- return get_current_task_from_pgcstack (ctx. builder , ctx.types ().T_size , ctx. pgcstack );
6526+ return get_current_task (ctx, ctx.types ().T_pjlvalue );
64876527}
64886528
64896529// Get PTLS through current task.
@@ -6495,20 +6535,20 @@ static Value *get_current_ptls(jl_codectx_t &ctx)
64956535// Get the address of the world age of the current task
64966536static Value *get_last_age_field (jl_codectx_t &ctx)
64976537{
6498- Value *ct = get_current_task (ctx);
6538+ Value *ct = get_current_task (ctx, ctx. types (). T_size -> getPointerTo () );
64996539 return ctx.builder .CreateInBoundsGEP (
65006540 ctx.types ().T_size ,
6501- ctx. builder . CreateBitCast (ct, ctx. types (). T_size -> getPointerTo ()) ,
6541+ ct ,
65026542 ConstantInt::get (ctx.types ().T_size , offsetof (jl_task_t , world_age) / ctx.types ().sizeof_ptr ),
65036543 " world_age" );
65046544}
65056545
65066546static Value *get_scope_field (jl_codectx_t &ctx)
65076547{
6508- Value *ct = get_current_task (ctx);
6548+ Value *ct = get_current_task (ctx, ctx. types (). T_prjlvalue -> getPointerTo () );
65096549 return ctx.builder .CreateInBoundsGEP (
65106550 ctx.types ().T_prjlvalue ,
6511- ctx. builder . CreateBitCast (ct, ctx. types (). T_prjlvalue -> getPointerTo ()) ,
6551+ ct ,
65126552 ConstantInt::get (ctx.types ().T_size , offsetof (jl_task_t , scope) / ctx.types ().sizeof_ptr ),
65136553 " current_scope" );
65146554}
@@ -9156,12 +9196,12 @@ static jl_llvm_functions_t
91569196 if (lname) {
91579197 // Save exception stack depth at enter for use in pop_exception
91589198 Value *excstack_state =
9159- ctx.builder .CreateCall (prepare_call (jl_excstack_state_func));
9199+ ctx.builder .CreateCall (prepare_call (jl_excstack_state_func), { get_current_task (ctx)} );
91609200 assert (!ctx.ssavalue_assigned [cursor]);
91619201 ctx.SAvalues [cursor] = jl_cgval_t (excstack_state, (jl_value_t *)jl_ulong_type, NULL );
91629202 ctx.ssavalue_assigned [cursor] = true ;
91639203 // Actually enter the exception frame
9164- CallInst *sj = ctx.builder .CreateCall (prepare_call (except_enter_func));
9204+ CallInst *sj = ctx.builder .CreateCall (prepare_call (except_enter_func), { get_current_task (ctx)} );
91659205 // We need to mark this on the call site as well. See issue #6757
91669206 sj->setCanReturnTwice ();
91679207 Value *isz = ctx.builder .CreateICmpEQ (sj, ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), 0 ));
@@ -9174,8 +9214,7 @@ static jl_llvm_functions_t
91749214 ctx.builder .CreateCondBr (isz, tryblk, catchpop);
91759215 ctx.builder .SetInsertPoint (catchpop);
91769216 {
9177- ctx.builder .CreateCall (prepare_call (jlleave_func),
9178- ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), 1 ));
9217+ ctx.builder .CreateCall (prepare_call (jlleave_func), {get_current_task (ctx), ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), 1 )});
91799218 if (old_scope) {
91809219 scope_ai.decorateInst (
91819220 ctx.builder .CreateAlignedStore (old_scope, scope_ptr, ctx.types ().alignof_ptr ));
@@ -9542,7 +9581,7 @@ jl_llvm_functions_t jl_emit_code(
95429581 decls.functionObject = " " ;
95439582 decls.specFunctionObject = " " ;
95449583 jl_printf ((JL_STREAM*)STDERR_FILENO, " Internal error: encountered unexpected error during compilation of %s:\n " , mname.c_str ());
9545- jl_static_show ((JL_STREAM*)STDERR_FILENO, jl_current_exception ());
9584+ jl_static_show ((JL_STREAM*)STDERR_FILENO, jl_current_exception (jl_current_task ));
95469585 jl_printf ((JL_STREAM*)STDERR_FILENO, " \n " );
95479586 jlbacktrace (); // written to STDERR_FILENO
95489587#ifndef JL_NDEBUG
@@ -9849,6 +9888,7 @@ static void init_jit_functions(void)
98499888 add_named_global (jlgenericfunction_func, &jl_generic_function_def);
98509889 add_named_global (jlenter_func, &jl_enter_handler);
98519890 add_named_global (jl_current_exception_func, &jl_current_exception);
9891+ add_named_global (jlleave_noexcept_func, &jl_pop_handler_noexcept);
98529892 add_named_global (jlleave_func, &jl_pop_handler);
98539893 add_named_global (jl_restore_excstack_func, &jl_restore_excstack);
98549894 add_named_global (jl_excstack_state_func, &jl_excstack_state);
0 commit comments