From 7d46071d89f2aad6e6354514710fd65a3f8bc1af Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Sun, 21 Feb 2021 18:41:12 -0500 Subject: [PATCH] codegen: define return_roots in normalized form (#39745) LLVM will switch to this form, so it is preferable to start that way. Refs Matcha in #39641 (cherry picked from commit f879cd159da8cb6110028702b787e6e7f816ca12) --- src/codegen.cpp | 18 +++++++++--------- src/llvm-late-gc-lowering.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index b6e52ecbd60913..02076a82e99092 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -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++; } @@ -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; @@ -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++) { @@ -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++; } @@ -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); diff --git a/src/llvm-late-gc-lowering.cpp b/src/llvm-late-gc-lowering.cpp index bf842a1182678b..99ff45cf618159 100644 --- a/src/llvm-late-gc-lowering.cpp +++ b/src/llvm-late-gc-lowering.cpp @@ -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); @@ -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; @@ -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?);