Skip to content

Commit

Permalink
Derive !noalias from !tbaa for most loads/stores
Browse files Browse the repository at this point in the history
This is an interim solution that derives the correct `!noalias`
region from the existing TBAA information.

Later we will want to:
    - Revise the TBAA hierarchy to remove region information
    - Delete `jl_aliasinfo_t::fromTBAA()`
    - Update `jl_cgval_t` to store a `jl_aliasinfo_t`
  • Loading branch information
topolarity committed Feb 1, 2023
1 parent 0f0d425 commit 54d3b1a
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 182 deletions.
30 changes: 20 additions & 10 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,12 @@ static Value *julia_to_native(
// since those are immutable.
Value *slot = emit_static_alloca(ctx, to);
if (!jvinfo.ispointer()) {
tbaa_decorate(jvinfo.tbaa, ctx.builder.CreateStore(emit_unbox(ctx, to, jvinfo, jlto), slot));
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, jvinfo.tbaa);
ai.decorateInst(ctx.builder.CreateStore(emit_unbox(ctx, to, jvinfo, jlto), slot));
}
else {
emit_memcpy(ctx, slot, jvinfo.tbaa, jvinfo, jl_datatype_size(jlto), julia_alignment(jlto));
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, jvinfo.tbaa);
emit_memcpy(ctx, slot, ai, jvinfo, jl_datatype_size(jlto), julia_alignment(jlto));
}
return slot;
}
Expand Down Expand Up @@ -1571,7 +1573,8 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
const int tid_offset = offsetof(jl_task_t, tid);
Value *ptid = ctx.builder.CreateInBoundsGEP(getInt16Ty(ctx.builder.getContext()), ptask_i16, ConstantInt::get(getSizeTy(ctx.builder.getContext()), tid_offset / sizeof(int16_t)));
LoadInst *tid = ctx.builder.CreateAlignedLoad(getInt16Ty(ctx.builder.getContext()), ptid, Align(sizeof(int16_t)));
tbaa_decorate(ctx.tbaa().tbaa_gcframe, tid);
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_gcframe);
ai.decorateInst(tid);
return mark_or_box_ccall_result(ctx, tid, retboxed, rt, unionall, static_rt);
}
else if (is_libjulia_func(jl_gc_disable_finalizers_internal)
Expand Down Expand Up @@ -1675,8 +1678,10 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
len = ctx.builder.CreateAlignedLoad(getSizeTy(ctx.builder.getContext()), ptr, Align(sizeof(size_t)));
// Only mark with TBAA if we are sure about the type.
// This could otherwise be in a dead branch
if (svecv.typ == (jl_value_t*)jl_simplevector_type)
tbaa_decorate(ctx.tbaa().tbaa_const, cast<Instruction>(len));
if (svecv.typ == (jl_value_t*)jl_simplevector_type) {
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
ai.decorateInst(cast<Instruction>(len));
}
MDBuilder MDB(ctx.builder.getContext());
auto rng = MDB.createRange(
Constant::getNullValue(getSizeTy(ctx.builder.getContext())), ConstantInt::get(getSizeTy(ctx.builder.getContext()), INTPTR_MAX / sizeof(void*) - 1));
Expand All @@ -1701,8 +1706,10 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
load->setAtomic(AtomicOrdering::Unordered);
// Only mark with TBAA if we are sure about the type.
// This could otherwise be in a dead branch
if (svecv.typ == (jl_value_t*)jl_simplevector_type)
tbaa_decorate(ctx.tbaa().tbaa_const, load);
if (svecv.typ == (jl_value_t*)jl_simplevector_type) {
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
ai.decorateInst(load);
}
JL_GC_POP();
return mark_or_box_ccall_result(ctx, load, retboxed, rt, unionall, static_rt);
}
Expand Down Expand Up @@ -1736,7 +1743,8 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
Value *slot_addr = ctx.builder.CreateInBoundsGEP(ctx.types().T_prjlvalue, arrayptr, idx);
LoadInst *load = ctx.builder.CreateAlignedLoad(ctx.types().T_prjlvalue, slot_addr, Align(sizeof(void*)));
load->setAtomic(AtomicOrdering::Unordered);
tbaa_decorate(ctx.tbaa().tbaa_ptrarraybuf, load);
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_ptrarraybuf);
ai.decorateInst(load);
Value *res = ctx.builder.CreateZExt(ctx.builder.CreateICmpNE(load, Constant::getNullValue(ctx.types().T_prjlvalue)), getInt32Ty(ctx.builder.getContext()));
JL_GC_POP();
return mark_or_box_ccall_result(ctx, res, retboxed, rt, unionall, static_rt);
Expand Down Expand Up @@ -1838,7 +1846,8 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
Value *ph1 = emit_bitcast(ctx, decay_derived(ctx, boxed(ctx, val)), getSizePtrTy(ctx.builder.getContext()));
Value *ph2 = ctx.builder.CreateInBoundsGEP(getSizeTy(ctx.builder.getContext()), ph1, ConstantInt::get(getSizeTy(ctx.builder.getContext()), hash_offset / sizeof(size_t)));
LoadInst *hashval = ctx.builder.CreateAlignedLoad(getSizeTy(ctx.builder.getContext()), ph2, Align(sizeof(size_t)));
tbaa_decorate(ctx.tbaa().tbaa_const, hashval);
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
ai.decorateInst(hashval);
return mark_or_box_ccall_result(ctx, hashval, retboxed, rt, unionall, static_rt);
}
else if (!val.isboxed) {
Expand Down Expand Up @@ -2128,7 +2137,8 @@ jl_cgval_t function_sig_t::emit_a_ccall(
auto slot = emit_static_alloca(ctx, resultTy);
slot->setAlignment(Align(boxalign));
ctx.builder.CreateAlignedStore(result, slot, Align(boxalign));
emit_memcpy(ctx, strct, tbaa, slot, tbaa, rtsz, boxalign);
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa);
emit_memcpy(ctx, strct, ai, slot, ai, rtsz, boxalign);
}
else {
init_bits_value(ctx, strct, result, tbaa, boxalign);
Expand Down
Loading

0 comments on commit 54d3b1a

Please sign in to comment.