[Clang] noinline call site attribute
authorDávid Bolvanský <david.bolvansky@gmail.com>
Mon, 28 Feb 2022 20:20:59 +0000 (21:20 +0100)
committerDávid Bolvanský <david.bolvansky@gmail.com>
Mon, 28 Feb 2022 20:21:17 +0000 (21:21 +0100)
commit223b8240223541d3feb0c96b7f9bac114cd72f46
tree86c7d3862d6444c5ae2b579e0dff3fde04b80ef2
parent96dea2015554d1bf1e095ea82bc57d9229bd5fd5
[Clang] noinline call site attribute

Motivation:

```
int foo(int x, int y) { // any compiler will happily inline this function
    return x / y;
}

int test(int x, int y) {
    int r = 0;
    [[clang::noinline]] r += foo(x, y); // for some reason we don't want any inlining here
    return r;
}

```

In 2018, @kuhar proposed "Introduce per-callsite inline intrinsics"  in https://reviews.llvm.org/D51200 to solve this motivation case (and many others).

This patch solves this problem with call site attribute. The implementation is "smaller" wrt approach which uses new intrinsics and thanks to https://reviews.llvm.org/D79121 (Add nomerge statement attribute to clang), we have got some basic infrastructure to deal with attrs on statements with call expressions.

GCC devs are more inclined to call attribute solution as well, as builtins are problematic for them - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104187. But they have no patch proposal yet so..  We have free hands here.

If this approach makes sense, next future steps would be support for call site attributes for always_inline / flatten.

Reviewed By: aaron.ballman, kuhar

Differential Revision: https://reviews.llvm.org/D119061
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/CodeGen/attr-noinline.cpp [new file with mode: 0644]
clang/test/Parser/stmt-attributes.c
clang/test/Sema/attr-noinline.c
clang/test/Sema/attr-noinline.cpp [new file with mode: 0644]