Skip to content

Commit

Permalink
codegen: define return_roots in normalized form (#39745)
Browse files Browse the repository at this point in the history
LLVM will switch to this form, so it is preferable to start that way.

Refs Matcha in #39641

(cherry picked from commit f879cd1)
  • Loading branch information
vtjnash authored and staticfloat committed Dec 22, 2022
1 parent 8071f26 commit 7d46071
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3307,8 +3307,7 @@ static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, jl_method_instance_
}

if (returninfo.return_roots) {
AllocaInst *return_roots = emit_static_alloca(ctx, T_prjlvalue);
return_roots->setOperand(0, ConstantInt::get(T_int32, returninfo.return_roots));
AllocaInst *return_roots = emit_static_alloca(ctx, ArrayType::get(T_prjlvalue, returninfo.return_roots));
argvals[idx] = return_roots;
idx++;
}
Expand Down Expand Up @@ -4708,8 +4707,11 @@ static void emit_cfunc_invalidate(
break;
}
case jl_returninfo_t::SRet: {
if (return_roots)
ctx.builder.CreateStore(gf_ret, gf_thunk->arg_begin() + 1);
if (return_roots) {
Value *root1 = gf_thunk->arg_begin() + 1; // root1 has type [n x {}*]*
root1 = ctx.builder.CreateConstInBoundsGEP2_32(root1->getType()->getPointerElementType(), root1, 0, 0);
ctx.builder.CreateStore(gf_ret, root1);
}
emit_memcpy(ctx, &*gf_thunk->arg_begin(), nullptr, gf_ret, nullptr, jl_datatype_size(rettype), julia_alignment(rettype));
ctx.builder.CreateRetVoid();
break;
Expand Down Expand Up @@ -5085,8 +5087,7 @@ static Function* gen_cfun_wrapper(
args.push_back(result);
}
if (returninfo.return_roots) {
AllocaInst *return_roots = emit_static_alloca(ctx, T_prjlvalue);
return_roots->setOperand(0, ConstantInt::get(T_int32, returninfo.return_roots));
AllocaInst *return_roots = emit_static_alloca(ctx, ArrayType::get(T_prjlvalue, returninfo.return_roots));
args.push_back(return_roots);
}
for (size_t i = 0; i < nargs + 1; i++) {
Expand Down Expand Up @@ -5506,8 +5507,7 @@ static Function *gen_invoke_wrapper(jl_method_instance_t *lam, jl_value_t *jlret
break;
}
if (f.return_roots) {
AllocaInst *return_roots = emit_static_alloca(ctx, T_prjlvalue);
return_roots->setOperand(0, ConstantInt::get(T_int32, f.return_roots));
AllocaInst *return_roots = emit_static_alloca(ctx, ArrayType::get(T_prjlvalue, f.return_roots));
args[idx] = return_roots;
idx++;
}
Expand Down Expand Up @@ -5654,7 +5654,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, String
}

if (props.return_roots) {
fsig.push_back(T_pprjlvalue);
fsig.push_back(ArrayType::get(T_prjlvalue, props.return_roots)->getPointerTo(0));
unsigned argno = fsig.size();
attributes = attributes.addAttribute(jl_LLVMContext, argno, Attribute::NoAlias);
attributes = attributes.addAttribute(jl_LLVMContext, argno, Attribute::NoCapture);
Expand Down
8 changes: 4 additions & 4 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,8 +1762,8 @@ unsigned TrackWithShadow(Value *Src, Type *STy, bool isptr, Value *Dst, IRBuilde
auto Ptrs = ExtractTrackedValues(Src, STy, isptr, irbuilder);
for (unsigned i = 0; i < Ptrs.size(); ++i) {
Value *Elem = Ptrs[i];
assert(Elem->getType()->isPointerTy());
Value *Slot = irbuilder.CreateConstInBoundsGEP1_32(Elem->getType(), Dst, i);
Type *ET = Dst->getType()->getPointerElementType(); // Dst has type `[n x {}*]*`
Value *Slot = irbuilder.CreateConstInBoundsGEP2_32(ET, Dst, 0, i);
StoreInst *shadowStore = irbuilder.CreateAlignedStore(Elem, Slot, Align(sizeof(void*)));
shadowStore->setOrdering(AtomicOrdering::NotAtomic);
// TODO: shadowStore->setMetadata(LLVMContext::MD_tbaa, tbaa_gcframe);
Expand All @@ -1790,7 +1790,7 @@ void LateLowerGCFrame::MaybeTrackDst(State &S, MemTransferInst *MI) {
// Src = new BitCastInst(Src, STy->getPointerTo(MI->getSourceAddressSpace()), "", MI);
// auto &Shadow = S.ShadowAllocas[AI];
// if (!Shadow)
// Shadow = new AllocaInst(T_prjlvalue, 0, ConstantInt::get(T_int32, nroots), "", MI);
// Shadow = new AllocaInst(ArrayType::get(T_prjlvalue, nroots), 0, "", MI);
// AI = Shadow;
// unsigned count = TrackWithShadow(Src, STy, true, AI, IRBuilder<>(MI));
// assert(count == tracked.count); (void)count;
Expand Down Expand Up @@ -1826,7 +1826,7 @@ void LateLowerGCFrame::MaybeTrackStore(State &S, StoreInst *I) {
// track the Store with a Shadow
//auto &Shadow = S.ShadowAllocas[AI];
//if (!Shadow)
// Shadow = new AllocaInst(T_prjlvalue, 0, ConstantInt::get(T_int32, tracked.count), "", MI);
// Shadow = new AllocaInst(ArrayType::get(T_prjlvalue, tracked.count), 0, "", MI);
//AI = Shadow;
//Value *Src = I->getValueOperand();
//unsigned count = TrackWithShadow(Src, Src->getType(), false, AI, MI, TODO which slots are we actually clobbering?);
Expand Down

0 comments on commit 7d46071

Please sign in to comment.