]> granicus.if.org Git - clang/commit
Always_inline codegen rewrite.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 11 Sep 2015 20:29:07 +0000 (20:29 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 11 Sep 2015 20:29:07 +0000 (20:29 +0000)
commitbfffdd3dff15236e9cbed4f97015ea394031306b
treec3ab5bc90db492bdf27169928d48c003a9c2680b
parentf78dda92f5038f2bcb4aad369c9f07669a107613
Always_inline codegen rewrite.

Current implementation may end up emitting an undefined reference for
an "inline __attribute__((always_inline))" function by generating an
"available_externally alwaysinline" IR function for it and then failing to
inline all the calls. This happens when a call to such function is in dead
code. As the inliner is an SCC pass, it does not process dead code.

Libc++ relies on the compiler never emitting such undefined reference.

With this patch, we emit a pair of
1. internal alwaysinline definition (called F.alwaysinline)
2a. A stub F() { musttail call F.alwaysinline }
  -- or, depending on the linkage --
2b. A declaration of F.

The frontend ensures that F.inlinefunction is only used for direct
calls, and the stub is used for everything else (taking the address of
the function, really). Declaration (2b) is emitted in the case when
"inline" is meant for inlining only (like __gnu_inline__ and some
other cases).

This approach, among other nice properties, ensures that alwaysinline
functions are always internal, making it impossible for a direct call
to such function to produce an undefined symbol reference.

This patch is based on ideas by Chandler Carruth and Richard Smith.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247465 91177308-0d34-0410-b5e6-96231b3b80d8
16 files changed:
lib/CodeGen/CGCXX.cpp
lib/CodeGen/CGClass.cpp
lib/CodeGen/CGOpenMPRuntime.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h
lib/CodeGen/ItaniumCXXABI.cpp
test/CodeGen/always-inline.c
test/CodeGen/always_inline-unused.c [new file with mode: 0644]
test/CodeGen/always_inline-wrappers.c [new file with mode: 0644]
test/CodeGen/always_inline.c
test/CodeGen/function-attributes.c
test/CodeGen/pr9614.c
test/CodeGenCXX/alwaysinline.cpp [new file with mode: 0644]
test/Frontend/optimization-remark-line-directive.c
test/Frontend/optimization-remark.c
test/Modules/cxx-irgen.cpp