[PATCH] D101011: [Attr] Add "noipa" function attribute

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 22 12:03:48 PDT 2021


dblaikie added a comment.

In D101011#2709755 <https://reviews.llvm.org/D101011#2709755>, @dblaikie wrote:

> In D101011#2709748 <https://reviews.llvm.org/D101011#2709748>, @xbolva00 wrote:
>
>> GCC docs: This attribute implies noinline, noclone and no_icf attributes. So for example:
>>
>>   diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
>>   index 6b966e7ca133..a13b1755cedf 100644
>>   --- a/clang/lib/CodeGen/CodeGenModule.cpp
>>   +++ b/clang/lib/CodeGen/CodeGenModule.cpp
>>   @@ -1757,6 +1757,10 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
>>        // Naked implies noinline: we should not be inlining such functions.
>>        B.addAttribute(llvm::Attribute::Naked);
>>        B.addAttribute(llvm::Attribute::NoInline);
>>   +  } else if (D->hasAttr<NoIPAAttr>()) {
>>   +    // NoIPA implies noinline: we should not be inlining such functions.
>>   +    B.addAttribute(llvm::Attribute::NoIPA);
>>   +    B.addAttribute(llvm::Attribute::NoInline);
>>      } else if (D->hasAttr<NoDuplicateAttr>()) {
>>        B.addAttribute(llvm::Attribute::NoDuplicate);
>>      } else if (D->hasAttr<NoInlineAttr>() && !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
>>
>> (just PoC, not tested)
>
> I think there's a reasonable argument to be made for keeping the attributes orthogonal - to implement the GCC compatible support in Clang we can always add both attributes in Clang's IRGen.

This also avoids the awkwardness of the optnone-requires-noinline situation (where adding optnone means validation failures until you add noinline too) - or if we made it implied like your patch does - then things get weird on roundtrip (the attribute gets added when parsing the IR? so the output IR is different from the input IR).

Hmm, I guess the naked-implies-noinline code above is a pretty good existence proof if we went that route, though. So probably not the worst design choice. Oh, hmm - if we only add the "implies" when parsing - what happens if someone makes an IR module in-memory via the C++ API? Looks like Clang has to intentionally add both attributes... not especially ergonomic.

(though that does mean if we later wanted to separate these ideas it would be difficult - because there could be code only adding Naked without noinline and now we'd be changing the behavior of that. (at least with the optnone-requires-noinline if we do remove that constraint existing users won't be adversely effected because they have to add both... well, in theory - I guess that's probably only enforced on reading, so if someone makes only in-memory IR they wouldn't see the constraint and they'd have problems)

ugh. Yeah, more reasons not to tie attributes together like this, I suspect.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101011/new/

https://reviews.llvm.org/D101011



More information about the llvm-commits mailing list