Skip to content

Commit a375fe8

Browse files
authored
codegen: cleanup some Attributes handling (JuliaLang#45666)
- Try to avoid making intermediate AttributeSet and AttributeList objects that we do not need. - Remove unnecessary bitcasts in new julia.call parameters. - Try to improve sret reuse: as pointed out in https://discourse.llvm.org/t/optimizing-sret-on-caller-side/60660 we are missing some attributes needed here to avoid an extra memcpy. - Use new NoUndef attribute. - Remove "thunk" attribute that is unneeded now.
1 parent ec0027f commit a375fe8

File tree

7 files changed

+256
-167
lines changed

7 files changed

+256
-167
lines changed

src/ccall.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ std::string generate_func_sig(const char *fname)
10671067
{
10681068
assert(rt && !jl_is_abstract_ref_type(rt));
10691069

1070-
std::vector<AttrBuilder> paramattrs;
1070+
std::vector<AttributeSet> paramattrs;
10711071
std::unique_ptr<AbiLayout> abi;
10721072
if (llvmcall)
10731073
abi.reset(new ABI_LLVMLayout());
@@ -1094,7 +1094,7 @@ std::string generate_func_sig(const char *fname)
10941094
retattrs.addStructRetAttr(lrt);
10951095
#endif
10961096
retattrs.addAttribute(Attribute::NoAlias);
1097-
paramattrs.push_back(std::move(retattrs));
1097+
paramattrs.push_back(AttributeSet::get(LLVMCtx, retattrs));
10981098
fargt_sig.push_back(PointerType::get(lrt, 0));
10991099
sret = 1;
11001100
prt = lrt;
@@ -1183,25 +1183,18 @@ std::string generate_func_sig(const char *fname)
11831183
fargt.push_back(t);
11841184
fargt_isboxed.push_back(isboxed);
11851185
fargt_sig.push_back(pat);
1186-
#if JL_LLVM_VERSION >= 140000
1187-
paramattrs.push_back(AttrBuilder(LLVMCtx, AttributeSet::get(LLVMCtx, ab)));
1188-
#else
11891186
paramattrs.push_back(AttributeSet::get(LLVMCtx, ab));
1190-
#endif
11911187
}
11921188

1193-
for (size_t i = 0; i < nccallargs + sret; ++i) {
1194-
const auto &as = paramattrs.at(i);
1195-
if (!as.hasAttributes())
1196-
continue;
1197-
attributes = addAttributesAtIndex(attributes, LLVMCtx, i + 1, as);
1198-
}
1189+
AttributeSet FnAttrs;
1190+
AttributeSet RetAttrs;
11991191
// If return value is boxed it must be non-null.
12001192
if (retboxed)
1201-
attributes = addRetAttribute(attributes, LLVMCtx, Attribute::NonNull);
1202-
if (rt == jl_bottom_type) {
1203-
attributes = addFnAttribute(attributes, LLVMCtx, Attribute::NoReturn);
1204-
}
1193+
RetAttrs = RetAttrs.addAttribute(LLVMCtx, Attribute::NonNull);
1194+
if (rt == jl_bottom_type)
1195+
FnAttrs = FnAttrs.addAttribute(LLVMCtx, Attribute::NoReturn);
1196+
assert(attributes.isEmpty());
1197+
attributes = AttributeList::get(LLVMCtx, FnAttrs, RetAttrs, paramattrs);
12051198
return "";
12061199
}
12071200
};

src/cgutils.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,21 +424,16 @@ static unsigned julia_alignment(jl_value_t *jt)
424424
return alignment;
425425
}
426426

427-
static inline void maybe_mark_argument_dereferenceable(Argument *A, jl_value_t *jt)
427+
static inline void maybe_mark_argument_dereferenceable(AttrBuilder &B, jl_value_t *jt)
428428
{
429-
#if JL_LLVM_VERSION >= 140000
430-
AttrBuilder B(A->getContext());
431-
#else
432-
AttrBuilder B;
433-
#endif
434429
B.addAttribute(Attribute::NonNull);
430+
B.addAttribute(Attribute::NoUndef);
435431
// The `dereferencable` below does not imply `nonnull` for non addrspace(0) pointers.
436432
size_t size = dereferenceable_size(jt);
437433
if (size) {
438434
B.addDereferenceableAttr(size);
439435
B.addAlignmentAttr(julia_alignment(jt));
440436
}
441-
A->addAttrs(B);
442437
}
443438

444439
static inline Instruction *maybe_mark_load_dereferenceable(Instruction *LI, bool can_be_null,

0 commit comments

Comments
 (0)