Remove LLVM attribute removal

This was necessary before, because `declare_raw_fn` would always apply
the default optimization attributes to every declared function,
and then `attributes::from_fn_attrs` would have to remove the default
attributes in the case of, e.g. `#[optimize(speed)]` in a `-Os` build.

However, every relevant callsite of `declare_raw_fn` (i.e. where we
actually generate code for the function, and not e.g. a call to an
intrinsic, where optimization attributes don't [?] matter)
calls `from_fn_attrs`, so we can simply remove the attribute setting
from `declare_raw_fn`, and rely on `from_fn_attrs` to apply the correct
attributes all at once.
This commit is contained in:
Erik Desjardins 2022-02-21 14:47:56 -05:00
parent b07d59f794
commit dce14cfacc
5 changed files with 13 additions and 87 deletions

View file

@ -250,38 +250,12 @@ template<typename T> static inline void AddAttributes(T *t, unsigned Index,
t->setAttributes(PALNew);
}
template<typename T> static inline void RemoveAttributes(T *t, unsigned Index,
LLVMRustAttribute *RustAttrs,
size_t RustAttrsLen) {
AttributeList PAL = t->getAttributes();
AttributeList PALNew;
#if LLVM_VERSION_LT(14, 0)
AttrBuilder B;
for (LLVMRustAttribute RustAttr : makeArrayRef(RustAttrs, RustAttrsLen))
B.addAttribute(fromRust(RustAttr));
PALNew = PAL.removeAttributes(t->getContext(), Index, B);
#else
AttributeMask Mask;
for (LLVMRustAttribute RustAttr : makeArrayRef(RustAttrs, RustAttrsLen))
Mask.addAttribute(fromRust(RustAttr));
PALNew = PAL.removeAttributesAtIndex(t->getContext(), Index, Mask);
#endif
t->setAttributes(PALNew);
}
extern "C" void LLVMRustAddFunctionAttributes(LLVMValueRef Fn, unsigned Index,
LLVMAttributeRef *Attrs, size_t AttrsLen) {
Function *F = unwrap<Function>(Fn);
AddAttributes(F, Index, Attrs, AttrsLen);
}
extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, unsigned Index,
LLVMRustAttribute *RustAttrs,
size_t RustAttrsLen) {
Function *F = unwrap<Function>(Fn);
RemoveAttributes(F, Index, RustAttrs, RustAttrsLen);
}
extern "C" void LLVMRustAddCallSiteAttributes(LLVMValueRef Instr, unsigned Index,
LLVMAttributeRef *Attrs, size_t AttrsLen) {
CallBase *Call = unwrap<CallBase>(Instr);