]> granicus.if.org Git - clang/commit
Always_inline codegen rewrite.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Sat, 12 Sep 2015 01:07:37 +0000 (01:07 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Sat, 12 Sep 2015 01:07:37 +0000 (01:07 +0000)
commitb41a71b12364a73a2038f193fa38b9e86e3e0fc5
tree3bdb9cb5e0a9c5411ae5292902221e6fc76fc967
parentb9dc14a84e1b4debd7f12b2387f97592cd0c6aa5
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@247494 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