[PATCH] D51200: Introduce per-callsite inline intrinsics

Jakub Kuderski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 23 17:29:59 PDT 2018


kuhar created this revision.
kuhar added reviewers: rsmith, pcc, Prazek, sanjoy.
kuhar added a project: clang.
Herald added a subscriber: eraman.
Herald added a reviewer: grosser.

Traditionally, to force some inlining decisions one has to annotate function declarations with `__attribute__((always_inline))` or `__attribute__((noinline))`. One problem with these attributes is that they affect every call site. Always inlining or forbidding inlining may not be desirable in every context, and a workaround for that is creating a few copies of functions, each with a different inline attribute. Furthermore, it's not always feasible (in every project) to modify library code and introduce new function attributes there.

This patch introduces a new way of forcing inlining decisions on a per-callsite basis. This allows for more fine-grained control over inlining, without creating any duplicate functions. The two new intrinsics for controlling inlining are:

- `__builtin_always_inline(Foo())` -- inlines the function `Foo` at the callsite, if possible. Internally, this applies the `alwaysinline` attribute to the generated call instruction.
- `__builtin_no_inline(Foo())` -- forbids the function `Foo` to be inlined at the callsite. Internally, this applies the `noinline` attribute to the generated call instruction.

The inline intrinsics support function, function pointer, member function, member function pointer, virutal function, and operator calls. Support for constructor calls (`CXXTemporaryExpr`) should also be possible, but is not the part of this patch.


Repository:
  rC Clang

https://reviews.llvm.org/D51200

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/CodeGen/CGFunctionInfo.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenTypes.h
  lib/Sema/SemaChecking.cpp
  test/CodeGenCXX/inline_builtin_call.cpp
  test/Sema/inline-builtins.c
  test/SemaCXX/inline-builtins.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51200.162299.patch
Type: text/x-patch
Size: 42171 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180824/89f04d90/attachment-0001.bin>


More information about the cfe-commits mailing list