Skip to content

Commit 78c8244

Browse files
committed
Derive !noalias from !tbaa for most loads/stores
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`
1 parent 7313b7f commit 78c8244

File tree

4 files changed

+216
-170
lines changed

4 files changed

+216
-170
lines changed

src/ccall.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,12 @@ static Value *julia_to_native(
550550
// since those are immutable.
551551
Value *slot = emit_static_alloca(ctx, to);
552552
if (!jvinfo.ispointer()) {
553-
tbaa_decorate(jvinfo.tbaa, ctx.builder.CreateStore(emit_unbox(ctx, to, jvinfo, jlto), slot));
553+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, jvinfo.tbaa);
554+
ai.decorateInst(ctx.builder.CreateStore(emit_unbox(ctx, to, jvinfo, jlto), slot));
554555
}
555556
else {
556-
emit_memcpy(ctx, slot, jvinfo.tbaa, jvinfo, jl_datatype_size(jlto), julia_alignment(jlto));
557+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, jvinfo.tbaa);
558+
emit_memcpy(ctx, slot, ai, jvinfo, jl_datatype_size(jlto), julia_alignment(jlto));
557559
}
558560
return slot;
559561
}
@@ -1571,7 +1573,8 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
15711573
const int tid_offset = offsetof(jl_task_t, tid);
15721574
Value *ptid = ctx.builder.CreateInBoundsGEP(getInt16Ty(ctx.builder.getContext()), ptask_i16, ConstantInt::get(getSizeTy(ctx.builder.getContext()), tid_offset / sizeof(int16_t)));
15731575
LoadInst *tid = ctx.builder.CreateAlignedLoad(getInt16Ty(ctx.builder.getContext()), ptid, Align(sizeof(int16_t)));
1574-
tbaa_decorate(ctx.tbaa().tbaa_gcframe, tid);
1576+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_gcframe);
1577+
ai.decorateInst(tid);
15751578
return mark_or_box_ccall_result(ctx, tid, retboxed, rt, unionall, static_rt);
15761579
}
15771580
else if (is_libjulia_func(jl_gc_disable_finalizers_internal)
@@ -1675,8 +1678,10 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
16751678
len = ctx.builder.CreateAlignedLoad(getSizeTy(ctx.builder.getContext()), ptr, Align(sizeof(size_t)));
16761679
// Only mark with TBAA if we are sure about the type.
16771680
// This could otherwise be in a dead branch
1678-
if (svecv.typ == (jl_value_t*)jl_simplevector_type)
1679-
tbaa_decorate(ctx.tbaa().tbaa_const, cast<Instruction>(len));
1681+
if (svecv.typ == (jl_value_t*)jl_simplevector_type) {
1682+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
1683+
ai.decorateInst(cast<Instruction>(len));
1684+
}
16801685
MDBuilder MDB(ctx.builder.getContext());
16811686
auto rng = MDB.createRange(
16821687
Constant::getNullValue(getSizeTy(ctx.builder.getContext())), ConstantInt::get(getSizeTy(ctx.builder.getContext()), INTPTR_MAX / sizeof(void*) - 1));
@@ -1701,8 +1706,10 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
17011706
load->setAtomic(AtomicOrdering::Unordered);
17021707
// Only mark with TBAA if we are sure about the type.
17031708
// This could otherwise be in a dead branch
1704-
if (svecv.typ == (jl_value_t*)jl_simplevector_type)
1705-
tbaa_decorate(ctx.tbaa().tbaa_const, load);
1709+
if (svecv.typ == (jl_value_t*)jl_simplevector_type) {
1710+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
1711+
ai.decorateInst(load);
1712+
}
17061713
JL_GC_POP();
17071714
return mark_or_box_ccall_result(ctx, load, retboxed, rt, unionall, static_rt);
17081715
}
@@ -1736,7 +1743,8 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
17361743
Value *slot_addr = ctx.builder.CreateInBoundsGEP(ctx.types().T_prjlvalue, arrayptr, idx);
17371744
LoadInst *load = ctx.builder.CreateAlignedLoad(ctx.types().T_prjlvalue, slot_addr, Align(sizeof(void*)));
17381745
load->setAtomic(AtomicOrdering::Unordered);
1739-
tbaa_decorate(ctx.tbaa().tbaa_ptrarraybuf, load);
1746+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_ptrarraybuf);
1747+
ai.decorateInst(load);
17401748
Value *res = ctx.builder.CreateZExt(ctx.builder.CreateICmpNE(load, Constant::getNullValue(ctx.types().T_prjlvalue)), getInt32Ty(ctx.builder.getContext()));
17411749
JL_GC_POP();
17421750
return mark_or_box_ccall_result(ctx, res, retboxed, rt, unionall, static_rt);
@@ -1838,7 +1846,8 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
18381846
Value *ph1 = emit_bitcast(ctx, decay_derived(ctx, boxed(ctx, val)), getSizePtrTy(ctx.builder.getContext()));
18391847
Value *ph2 = ctx.builder.CreateInBoundsGEP(getSizeTy(ctx.builder.getContext()), ph1, ConstantInt::get(getSizeTy(ctx.builder.getContext()), hash_offset / sizeof(size_t)));
18401848
LoadInst *hashval = ctx.builder.CreateAlignedLoad(getSizeTy(ctx.builder.getContext()), ph2, Align(sizeof(size_t)));
1841-
tbaa_decorate(ctx.tbaa().tbaa_const, hashval);
1849+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
1850+
ai.decorateInst(hashval);
18421851
return mark_or_box_ccall_result(ctx, hashval, retboxed, rt, unionall, static_rt);
18431852
}
18441853
else if (!val.isboxed) {
@@ -2128,7 +2137,8 @@ jl_cgval_t function_sig_t::emit_a_ccall(
21282137
auto slot = emit_static_alloca(ctx, resultTy);
21292138
slot->setAlignment(Align(boxalign));
21302139
ctx.builder.CreateAlignedStore(result, slot, Align(boxalign));
2131-
emit_memcpy(ctx, strct, tbaa, slot, tbaa, rtsz, boxalign);
2140+
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa);
2141+
emit_memcpy(ctx, strct, ai, slot, ai, rtsz, boxalign);
21322142
}
21332143
else {
21342144
init_bits_value(ctx, strct, result, tbaa, boxalign);

0 commit comments

Comments
 (0)