Skip to content

Commit

Permalink
Fix debug level check and add types to allocations in the IR (#51338)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi authored Sep 18, 2023
1 parent a811406 commit 893fecc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3545,8 +3545,11 @@ static Value *boxed(jl_codectx_t &ctx, const jl_cgval_t &vinfo, bool is_promotab
originalAlloca->eraseFromParent();
ctx.builder.restoreIP(IP);
} else {
auto arg_typename = [&] JL_NOTSAFEPOINT {
return jl_symbol_name(((jl_datatype_t*)(jt))->name->name);
};
box = emit_allocobj(ctx, (jl_datatype_t*)jt);
setName(ctx.emission_context, box, "box");
setName(ctx.emission_context, box, "box" + StringRef("::") + arg_typename());
init_bits_cgval(ctx, box, vinfo, jl_is_mutable(jt) ? ctx.tbaa().tbaa_mutab : ctx.tbaa().tbaa_immut);
}
}
Expand Down Expand Up @@ -3879,6 +3882,9 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
assert(jl_is_datatype(ty));
assert(jl_is_concrete_type(ty));
jl_datatype_t *sty = (jl_datatype_t*)ty;
auto arg_typename = [&] JL_NOTSAFEPOINT {
return jl_symbol_name((sty)->name->name);
};
size_t nf = jl_datatype_nfields(sty);
if (nf > 0 || sty->name->mutabl) {
if (deserves_stack(ty)) {
Expand Down Expand Up @@ -3910,7 +3916,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
}
else {
strct = emit_static_alloca(ctx, lt);
setName(ctx.emission_context, strct, "newstruct");
setName(ctx.emission_context, strct, "new" + StringRef("::") + arg_typename());
if (tracked.count)
undef_derived_strct(ctx, strct, sty, ctx.tbaa().tbaa_stack);
}
Expand Down Expand Up @@ -4080,7 +4086,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
}
}
Value *strct = emit_allocobj(ctx, sty);
setName(ctx.emission_context, strct, "newstruct");
setName(ctx.emission_context, strct, "new" + StringRef("::") + arg_typename());
jl_cgval_t strctinfo = mark_julia_type(ctx, strct, true, ty);
strct = decay_derived(ctx, strct);
undef_derived_strct(ctx, strct, sty, strctinfo.tbaa);
Expand Down
2 changes: 1 addition & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7431,7 +7431,7 @@ static jl_llvm_functions_t
f = cast<Function>(returninfo.decl.getCallee());
has_sret = (returninfo.cc == jl_returninfo_t::SRet || returninfo.cc == jl_returninfo_t::Union);
jl_init_function(f, ctx.emission_context.TargetTriple);
if (ctx.emission_context.debug_level > 0) {
if (ctx.emission_context.debug_level >= 2) {
auto arg_typename = [&](size_t i) JL_NOTSAFEPOINT {
auto tp = jl_tparam(lam->specTypes, i);
return jl_is_datatype(tp) ? jl_symbol_name(((jl_datatype_t*)tp)->name->name) : "<unknown type>";
Expand Down
13 changes: 12 additions & 1 deletion test/llvmpasses/names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ function f7(a)
return a[2]
end

# COM: check write barrier names
# COM: check write barrier names and struct names
mutable struct Barrier
b
end

struct Named
x::Int
end
# CHECK-LABEL: define {{(swiftcc )?}}double @julia_f1
# CHECK-SAME: double %"a::Float64"
# CHECK-SAME: double %"b::Float64"
Expand Down Expand Up @@ -186,3 +189,11 @@ emit(f7,Tuple{Int,Int})
# CHECK: %child_bit
# CHECK: %child_not_marked
emit(Barrier, Int64)

# CHECK: define {{(swiftcc )?}}nonnull {} addrspace(10)* @julia_Barrier
# CHECK-SAME: %"b::Named"
# CHECK: %"new::Barrier"
# CHECK: %"box::Named"
# CHECK: %parent_bits
# CHECK: %parent_old_marked
emit(Barrier, Named)

0 comments on commit 893fecc

Please sign in to comment.