Skip to content

Commit

Permalink
Fix attributes and opaque pointer usage for LLVM15 (#49528)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Baraldi <[email protected]>
Co-authored-by: Prem Chintalapudi <[email protected]>
  • Loading branch information
3 people committed Apr 27, 2023
1 parent bf7bd3f commit 527117e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,10 +942,10 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, jl_aliasinfo_t const
const DataLayout &DL = jl_Module->getDataLayout();
auto srcty = cast<PointerType>(src->getType());
//TODO unsafe nonopaque pointer
auto srcel = srcty->getPointerElementType();
auto srcel = srcty->getNonOpaquePointerElementType();
auto dstty = cast<PointerType>(dst->getType());
//TODO unsafe nonopaque pointer
auto dstel = dstty->getPointerElementType();
auto dstel = dstty->getNonOpaquePointerElementType();
while (srcel->isArrayTy() && srcel->getArrayNumElements() == 1) {
src = ctx.builder.CreateConstInBoundsGEP2_32(srcel, src, 0, 0);
srcel = srcel->getArrayElementType();
Expand Down
25 changes: 16 additions & 9 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,15 +921,20 @@ static const auto jl_alloc_obj_func = new JuliaFunction<TypeFnContextAndSizeT>{
return FunctionType::get(T_prjlvalue,
{T_ppjlvalue, T_size, T_prjlvalue}, false);
},
[](LLVMContext &C) { return AttributeList::get(C,
AttributeSet::get(C, makeArrayRef({Attribute::getWithAllocSizeArgs(C, 1, None)})), // returns %1 bytes

Attributes(C, {Attribute::NoAlias, Attribute::NonNull,
[](LLVMContext &C) {
auto FnAttrs = AttrBuilder(C);
FnAttrs.addAllocSizeAttr(1, None); // returns %1 bytes
#if JL_LLVM_VERSION >= 150000
Attribute::get(C, Attribute::AllocKind, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned),
FnAttrs.addAllocKindAttr(AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned);
#endif
}),
None); },
auto RetAttrs = AttrBuilder(C);
RetAttrs.addAttribute(Attribute::NoAlias);
RetAttrs.addAttribute(Attribute::NonNull);
return AttributeList::get(C,
AttributeSet::get(C, FnAttrs),
AttributeSet::get(C, RetAttrs),
None);
},
};
static const auto jl_newbits_func = new JuliaFunction<>{
XSTR(jl_new_bits),
Expand Down Expand Up @@ -2349,7 +2354,11 @@ static void jl_init_function(Function *F, const Triple &TT)
attr.addStackAlignmentAttr(16);
}
if (TT.isOSWindows() && TT.getArch() == Triple::x86_64) {
#if JL_LLVM_VERSION < 150000
attr.addAttribute(Attribute::UWTable); // force NeedsWinEH
#else
attr.addUWTableAttr(llvm::UWTableKind::Default); // force NeedsWinEH
#endif
}
if (jl_fpo_disabled(TT))
attr.addAttribute("frame-pointer", "all");
Expand Down Expand Up @@ -6312,8 +6321,6 @@ static Function* gen_cfun_wrapper(
}
else if (!type_is_ghost(sig.lrt)) {
Type *prt = sig.prt;
if (sig.sret)
prt = sig.fargt_sig[0]->getContainedType(0); // sret is a PointerType
bool issigned = jl_signed_type && jl_subtype(declrt, (jl_value_t*)jl_signed_type);
Value *v = emit_unbox(ctx, sig.lrt, retval, retval.typ);
r = llvm_type_rewrite(ctx, v, prt, issigned);
Expand Down
4 changes: 2 additions & 2 deletions src/llvm-remove-addrspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AddrspaceRemoveTypeRemapper : public ValueMapTypeRemapper {
else {
//Remove once opaque pointer transition is complete
DstTy = PointerType::get(
remapType(Ty->getPointerElementType()),
remapType(Ty->getNonOpaquePointerElementType()),
ASRemapper(Ty->getAddressSpace()));
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ class AddrspaceRemoveValueMaterializer : public ValueMaterializer {
auto ptrty = cast<PointerType>(Src->getType()->getScalarType());
//Remove once opaque pointer transition is complete
if (!ptrty->isOpaque()) {
Type *SrcTy = remapType(ptrty->getPointerElementType());
Type *SrcTy = remapType(ptrty->getNonOpaquePointerElementType());
DstV = CE->getWithOperands(Ops, Ty, false, SrcTy);
}
}
Expand Down

2 comments on commit 527117e

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.

Please sign in to comment.