[PATCH] D108618: [CGCall] Add NoInline attr if presented for the target
Djordje Todorovic via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 26 06:20:15 PDT 2021
djtodoro added a comment.
In D108618#2964265 <https://reviews.llvm.org/D108618#2964265>, @rjmccall wrote:
> Why do you want to add `noinline` to a function declaration that lacks a definition?
If this won't be used at all I guess the compiler should throw a warning at least.
One example comes to my mind, and it includes LTO (and cross-compile unit inlining).
$ cat test-1.c
extern int __attribute__((noinline)) bar(void);
int foo() {
int v1 = bar();
if (v1 > 100)
return 0;
v1--;
return v1;
}
$ cat $ cat test-2.c
int __attribute__((always_inline)) bar(void);
int foo2() {
int v2 = bar();
if (v2 > 1000)
return 0;
v2++;
return v2;
}
$ cat test.c
#include <stdio.h>
extern int foo();
extern int foo2();
int bar() {
int x;
scanf("%d", &x);
++x;
return x;
}
int main()
{
int i = foo();
int j = foo2();
return i - j;
}
$ clang test.c -g -S -flto -emit-llvm
$ clang test-1.c -g -S -flto -emit-llvm
$ clang test-2.c -g -S -flto -emit-llvm
$ llvm-link -S -o linked.ll test-1.ll test-2.ll test.ll
$ opt -S -O1 linked.ll -o optimized.ll
Having these simple compile units, I can expect that compiler is able to inline the `bar()` into `foo2()` but not into `foo()`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108618/new/
https://reviews.llvm.org/D108618
More information about the cfe-commits
mailing list