[PATCH] D12087: always_inline codegen rewrite

Evgeniy Stepanov via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 17 11:07:55 PDT 2015


eugenis created this revision.
eugenis added reviewers: chandlerc, rsmith.
eugenis added a subscriber: cfe-commits.
eugenis set the repository for this revision to rL LLVM.

Currently always_inline definitions are emitted as (in most cases) an available_externally llvm function with an alwaysinline attribute. This is not exactly right: always_inline functions are NOT available externally, and, for example, libc++ uses this semantics to preserve ABI stability.

Emitting an undefined symbol for an always_inline function is always a bug. The current code can still do it in certain cases. 
 a. Inliner is an SCC pass. It traverses the graph starting from the roots, which are either main() function, or all externally-visible functions. Inlining does not happen in functions that are not reachable.
 b. Dead code elimination is not perfect. There are cases where a function will become unreachable due to some late optimizations and will still be emitted into the binary.

This patch changes the way always_inline functions are emitted in the Clang codegen to ensure this never happens. A function F is emitted as a pair of
 a. internal F.inlinefunction() alwaysinline { **original function body** }
and, depending on the function visibility, either 
 b1. declare F()
or
 b2. define external F() { musttail call F.inlinefunction() }

Frontend ensures that all direct calls go to F.inlinefunction().

This provides a simple invariant that all alwaysinline functions are internal, which can be checked in the IR verifier. Another invariant would be that alwaysinline functions never reach the backend.

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


Repository:
  rL LLVM

http://reviews.llvm.org/D12087

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGen/2008-05-19-AlwaysInline.c
  test/CodeGen/always-inline.c
  test/CodeGen/always_inline.c
  test/CodeGen/alwaysinline.c
  test/CodeGen/dllimport.c
  test/CodeGen/function-attributes.c
  test/CodeGen/pr9614.c
  test/CodeGenCXX/alwaysinline.cpp
  test/CodeGenCXX/dllimport.cpp
  test/Frontend/optimization-remark-line-directive.c
  test/Frontend/optimization-remark.c
  test/Modules/cxx-irgen.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12087.32327.patch
Type: text/x-patch
Size: 21413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150817/15ce93e8/attachment-0001.bin>


More information about the cfe-commits mailing list