@@ -4035,22 +4035,42 @@ callee is unavailable or if the callee has the ``noinline`` attribute.
40354035def 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