@@ -930,12 +930,12 @@ static const auto jlgetbindingorerror_func = new JuliaFunction<>{
930930 },
931931 nullptr ,
932932};
933- static const auto jlgetbindingwrorerror_func = new JuliaFunction<>{
934- XSTR (jl_get_binding_wr ),
933+ static const auto jlcheckbpwritable_func = new JuliaFunction<>{
934+ XSTR (jl_check_binding_currently_writable ),
935935 [](LLVMContext &C) {
936936 auto T_pjlvalue = JuliaType::get_pjlvalue_ty (C);
937- return FunctionType::get (T_pjlvalue ,
938- {T_pjlvalue, T_pjlvalue, getInt32Ty (C) }, false );
937+ return FunctionType::get (getVoidTy (C) ,
938+ {T_pjlvalue, T_pjlvalue, T_pjlvalue }, false );
939939 },
940940 nullptr ,
941941};
@@ -2098,8 +2098,6 @@ static Type *julia_type_to_llvm(jl_codectx_t &ctx, jl_value_t *jt, bool *isboxed
20982098static 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,
20992099 ArrayRef<const char *> ArgNames=None, unsigned nreq=0 );
21002100static jl_cgval_t emit_expr (jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval = -1 );
2101- static Value *global_binding_pointer (jl_codectx_t &ctx, jl_module_t *m, jl_sym_t *s,
2102- jl_binding_t **pbnd, bool assign, bool alloc);
21032101static jl_cgval_t emit_checked_var (jl_codectx_t &ctx, Value *bp, jl_sym_t *name, jl_value_t *scope, bool isvol, MDNode *tbaa);
21042102static jl_cgval_t emit_sparam (jl_codectx_t &ctx, size_t i);
21052103static Value *emit_condition (jl_codectx_t &ctx, const jl_cgval_t &condV, const Twine &msg);
@@ -3498,19 +3496,17 @@ static jl_cgval_t emit_globalop(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *s
34983496 bool issetglobal, bool isreplaceglobal, bool isswapglobal, bool ismodifyglobal, bool issetglobalonce,
34993497 const jl_cgval_t *modifyop, bool alloc)
35003498{
3501- jl_binding_t *bnd = NULL ;
3502- Value *bp = global_binding_pointer (ctx, mod, sym, &bnd, true , alloc);
3499+ jl_binding_t *bnd = jl_get_module_binding (mod, sym, 1 );
35033500 jl_binding_partition_t *bpart = jl_get_binding_partition_all (bnd, ctx.min_world , ctx.max_world );
3504- if (bp == NULL )
3505- return jl_cgval_t ();
3501+ Value *bp = julia_binding_gv (ctx, bnd);
35063502 if (bpart) {
35073503 jl_ptr_kind_union_t pku = jl_atomic_load_relaxed (&bpart->restriction );
3508- if (! jl_bkind_is_some_constant ( decode_restriction_kind (pku)) ) {
3504+ if (decode_restriction_kind (pku) == BINDING_KIND_GLOBAL ) {
35093505 jl_value_t *ty = decode_restriction_value (pku);
35103506 if (ty != nullptr ) {
35113507 const std::string fname = issetglobal ? " setglobal!" : isreplaceglobal ? " replaceglobal!" : isswapglobal ? " swapglobal!" : ismodifyglobal ? " modifyglobal!" : " setglobalonce!" ;
35123508 if (!ismodifyglobal) {
3513- // TODO: use typeassert in jl_check_binding_wr too
3509+ // TODO: use typeassert in jl_check_binding_assign_value too
35143510 emit_typecheck (ctx, rval, ty, " typeassert" );
35153511 rval = update_julia_type (ctx, rval, ty);
35163512 if (rval.typ == jl_bottom_type)
@@ -3545,6 +3541,8 @@ static jl_cgval_t emit_globalop(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *s
35453541 }
35463542 Value *m = literal_pointer_val (ctx, (jl_value_t *)mod);
35473543 Value *s = literal_pointer_val (ctx, (jl_value_t *)sym);
3544+ ctx.builder .CreateCall (prepare_call (jlcheckbpwritable_func),
3545+ { bp, m, s });
35483546 if (issetglobal) {
35493547 ctx.builder .CreateCall (prepare_call (jlcheckassign_func),
35503548 { bp, m, s, mark_callee_rooted (ctx, boxed (ctx, rval)) });
@@ -5991,85 +5989,6 @@ static void emit_hasnofield_error_ifnot(jl_codectx_t &ctx, Value *ok, jl_datatyp
59915989 ctx.builder .SetInsertPoint (ifok);
59925990}
59935991
5994- // returns a jl_ppvalue_t location for the global variable m.s
5995- // if the reference currently bound or assign == true,
5996- // pbnd will also be assigned with the binding address
5997- static Value *global_binding_pointer (jl_codectx_t &ctx, jl_module_t *m, jl_sym_t *s,
5998- jl_binding_t **pbnd, bool assign, bool alloc)
5999- {
6000- jl_binding_t *b = jl_get_module_binding (m, s, 1 );
6001- jl_binding_partition_t *bpart = jl_get_binding_partition_all (b, ctx.min_world , ctx.max_world );
6002- jl_ptr_kind_union_t pku = jl_atomic_load_relaxed (&bpart->restriction );
6003- if (assign) {
6004- if (jl_bkind_is_some_guard (decode_restriction_kind (pku)))
6005- // not yet declared
6006- b = NULL ;
6007- }
6008- else {
6009- if (jl_bkind_is_some_guard (decode_restriction_kind (pku))) {
6010- // try to look this up now
6011- b = jl_get_binding (m, s);
6012- bpart = jl_get_binding_partition_all (b, ctx.min_world , ctx.max_world );
6013- }
6014- pku = jl_walk_binding_inplace_all (&b, &bpart, ctx.min_world , ctx.max_world );
6015- }
6016- if (!b || !bpart) {
6017- // var not found. switch to delayed lookup.
6018- Constant *initnul = Constant::getNullValue (ctx.types ().T_pjlvalue );
6019- GlobalVariable *bindinggv = new GlobalVariable (*ctx.f ->getParent (), ctx.types ().T_pjlvalue ,
6020- false , GlobalVariable::PrivateLinkage, initnul, " jl_binding_ptr" ); // LLVM has bugs with nameless globals
6021- LoadInst *cachedval = ctx.builder .CreateAlignedLoad (ctx.types ().T_pjlvalue , bindinggv, Align (sizeof (void *)));
6022- setName (ctx.emission_context , cachedval, jl_symbol_name (m->name ) + StringRef (" ." ) + jl_symbol_name (s) + " .cached" );
6023- cachedval->setOrdering (AtomicOrdering::Unordered);
6024- BasicBlock *have_val = BasicBlock::Create (ctx.builder .getContext (), " found" );
6025- BasicBlock *not_found = BasicBlock::Create (ctx.builder .getContext (), " notfound" );
6026- BasicBlock *currentbb = ctx.builder .GetInsertBlock ();
6027- auto iscached = ctx.builder .CreateICmpNE (cachedval, initnul);
6028- setName (ctx.emission_context , iscached, " iscached" );
6029- ctx.builder .CreateCondBr (iscached, have_val, not_found);
6030- not_found->insertInto (ctx.f );
6031- ctx.builder .SetInsertPoint (not_found);
6032- Value *bval = nullptr ;
6033- if (assign) {
6034- bval = ctx.builder .CreateCall (prepare_call (jlgetbindingwrorerror_func),
6035- { literal_pointer_val (ctx, (jl_value_t *)m),
6036- literal_pointer_val (ctx, (jl_value_t *)s),
6037- ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), alloc)});
6038- } else {
6039- bval = ctx.builder .CreateCall (prepare_call (jlgetbindingorerror_func),
6040- { literal_pointer_val (ctx, (jl_value_t *)m),
6041- literal_pointer_val (ctx, (jl_value_t *)s)});
6042- }
6043- setName (ctx.emission_context , bval, jl_symbol_name (m->name ) + StringRef (" ." ) + jl_symbol_name (s) + " .found" );
6044- ctx.builder .CreateAlignedStore (bval, bindinggv, Align (sizeof (void *)))->setOrdering (AtomicOrdering::Release);
6045- ctx.builder .CreateBr (have_val);
6046- have_val->insertInto (ctx.f );
6047- ctx.builder .SetInsertPoint (have_val);
6048- PHINode *p = ctx.builder .CreatePHI (ctx.types ().T_pjlvalue , 2 );
6049- p->addIncoming (cachedval, currentbb);
6050- p->addIncoming (bval, not_found);
6051- setName (ctx.emission_context , p, jl_symbol_name (m->name ) + StringRef (" ." ) + jl_symbol_name (s));
6052- return p;
6053- }
6054- if (assign) {
6055- if (decode_restriction_kind (pku) != BINDING_KIND_GLOBAL && !jl_bkind_is_some_guard (decode_restriction_kind (pku))) {
6056- // this will fail at runtime, so defer to the runtime to create the error
6057- ctx.builder .CreateCall (prepare_call (jlgetbindingwrorerror_func),
6058- { literal_pointer_val (ctx, (jl_value_t *)m),
6059- literal_pointer_val (ctx, (jl_value_t *)s),
6060- ConstantInt::get (getInt32Ty (ctx.builder .getContext ()), alloc) });
6061- CreateTrap (ctx.builder );
6062- return NULL ;
6063- }
6064- }
6065- else {
6066- if (b->deprecated )
6067- cg_bdw (ctx, s, b);
6068- }
6069- *pbnd = b;
6070- return julia_binding_gv (ctx, b);
6071- }
6072-
60735992static jl_cgval_t emit_checked_var (jl_codectx_t &ctx, Value *bp, jl_sym_t *name, jl_value_t *scope, bool isvol, MDNode *tbaa)
60745993{
60755994 LoadInst *v = ctx.builder .CreateAlignedLoad (ctx.types ().T_prjlvalue , bp, Align (sizeof (void *)));
@@ -10184,7 +10103,7 @@ static void init_jit_functions(void)
1018410103 add_named_global (jltypeerror_func, &jl_type_error);
1018510104 add_named_global (jlcheckassign_func, &jl_checked_assignment);
1018610105 add_named_global (jlgetbindingorerror_func, &jl_get_binding_or_error);
10187- add_named_global (jlgetbindingwrorerror_func , &jl_get_binding_wr );
10106+ add_named_global (jlcheckbpwritable_func , &jl_check_binding_currently_writable );
1018810107 add_named_global (jlboundp_func, &jl_boundp);
1018910108 for (auto it : builtin_func_map ())
1019010109 add_named_global (it.second , it.first );
0 commit comments