Skip to content

Commit 2e07a17

Browse files
committed
Updated documentation
1 parent 6449d0f commit 2e07a17

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,18 @@ Attribute Changes in Clang
347347
- New format attributes ``gnu_printf``, ``gnu_scanf``, ``gnu_strftime`` and ``gnu_strfmon`` are added
348348
as aliases for ``printf``, ``scanf``, ``strftime`` and ``strfmon``. (#GH16219)
349349

350+
- Added the ``flatten_depth`` attribute, which provides a hint to the inliner to aggressively
351+
inline calls within the attributed function up to a specified depth. This attribute takes
352+
a single unsigned integer argument representing the requested depth of inlining. Unlike
353+
a strict limit, the requested depth is a hint that works cooperatively with other inlining
354+
mechanisms:
355+
356+
- Functions marked with ``always_inline`` will be inlined even if they exceed the requested depth
357+
- The compiler's cost model may choose to inline beyond the requested depth for beneficial cases
358+
(e.g., trivial wrapper functions)
359+
- Functions marked with ``noinline`` will not be inlined regardless of the requested depth
360+
- For recursive functions, the attribute applies the depth limit to prevent infinite inlining
361+
350362
Improvements to Clang's diagnostics
351363
-----------------------------------
352364
- Diagnostics messages now refer to ``structured binding`` instead of ``decomposition``,

clang/include/clang/Basic/AttrDocs.td

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4035,22 +4035,42 @@ callee is unavailable or if the callee has the ``noinline`` attribute.
40354035
def FlattenDepthDocs : Documentation {
40364036
let Category = DocCatFunction;
40374037
let Content = [{
4038-
The ``flatten_depth`` attribute causes calls within the attributed function and
4039-
their transitive callees to be inlined up to a specified depth, unless it is
4040-
impossible to do so (for example if the body of the callee is unavailable or if
4041-
the callee has the ``noinline`` attribute).
4038+
The ``flatten_depth`` attribute provides a hint to the inliner to aggressively
4039+
inline calls within the attributed function and their transitive callees up to
4040+
a specified depth in the call tree.
40424041

4043-
This attribute takes a single unsigned integer argument representing the maximum
4044-
depth of the call tree to inline. For example, ``__attribute__((flatten_depth(3)))``
4045-
will inline all calls within the function, then inline all calls within those
4046-
inlined functions (depth 2), and then inline all calls within those functions
4047-
(depth 3).
4042+
This attribute takes a single unsigned integer argument representing the
4043+
requested depth of inlining. For example, ``__attribute__((flatten_depth(3)))``
4044+
requests that calls within the function be inlined (depth 1), then calls within
4045+
those inlined functions (depth 2), and then calls within those functions (depth 3).
4046+
4047+
**Important**: This attribute is a requested depth hint, not a hard constraint.
4048+
The actual inlining behavior is subject to several considerations:
4049+
4050+
- **Interaction with other attributes**: Functions marked with ``always_inline``
4051+
will be inlined even if they exceed the requested depth. Similarly, functions
4052+
marked with ``noinline`` will not be inlined regardless of the requested depth.
4053+
4054+
- **Cost model decisions**: The compiler's inlining cost model may choose to
4055+
inline functions beyond the requested depth if doing so is deemed beneficial
4056+
(e.g., trivial wrapper functions or obvious optimization opportunities). This
4057+
prevents the attribute from becoming a footgun that blocks beneficial optimizations.
4058+
4059+
- **Insufficient call depth**: If the call tree is shallower than the requested
4060+
depth, the attribute simply inlines as far as the call tree allows.
4061+
4062+
- **Recursive functions**: For recursive calls, the attribute applies the depth
4063+
limit to prevent infinite inlining, but does not prevent recursion itself.
4064+
Recursive calls beyond the specified depth will not be inlined.
4065+
4066+
- **Unavailable function bodies**: Inlining cannot occur if the callee's body
4067+
is unavailable (e.g., external functions without definitions).
40484068

40494069
.. code-block:: c++
40504070

40514071
__attribute__((flatten_depth(3)))
40524072
void process_data() {
4053-
// All calls up to 3 levels deep in the call tree will be inlined
4073+
// Requests inlining of calls up to 3 levels deep in the call tree
40544074
}
40554075
}];
40564076
}

0 commit comments

Comments
 (0)