Forcing inlining of delegates and lazy

FinalEvilution FinalEvilution at gmail.com
Tue Sep 1 01:57:51 UTC 2026


On Tuesday, 1 September 2026 at 00:02:25 UTC, Mindy Batek (0xEAB) 
wrote:
> On Monday, 31 August 2026 at 17:36:55 UTC, ABrightLight wrote:
>> And the use of `pragma(inline)` hasn't helped.
>
> Have you tried LLVM’s `always_inline`?
> Supposedly available as `llvmAttr("always_inline")`.
>
> Docs: 
> <https://clang.llvm.org/docs/AttributeReference.html#always-inline-force-inline>

I just checked and ldc uses the LLVM IR version "alwaysinline"
`@llvmAttr("alwaysinline")`

I tested both the pragma and the llvmAttr version and both 
produce the exact same llvm ir
with an alwaysinline attribute attached to the function.

```
; Function Attrs: alwaysinline uwtable
define void @_D5clean5timesFiLvZv(i32 %n_arg, { ptr, ptr } 
%exp_arg) #1 {
...
attributes #1 = { alwaysinline uwtable "frame-pointer"="all" 
"target-cpu"="x86-64" "target-features"="+cx16" }
```

```
import std.stdio : writeln;
import ldc.attributes;

void main()
{
     int x;
     3.times(writeln(x++));
}

//pragma(inline, true)
//@llvmAttr("alwaysinline")
void times(int n, lazy void exp)
{
     while (n--)
         exp();
}
```


More information about the Digitalmars-d mailing list