LDC PGO on Windows

Imperatorn johan_forsberg_86 at hotmail.com
Tue Oct 17 13:00:54 UTC 2023


On Tuesday, 17 October 2023 at 08:59:52 UTC, Imperatorn wrote:
> On Monday, 16 October 2023 at 18:10:21 UTC, Imperatorn wrote:
>> On Monday, 16 October 2023 at 17:43:21 UTC, Imperatorn wrote:
>>> On Monday, 16 October 2023 at 17:13:04 UTC, Imperatorn wrote:
>>>> On Monday, 16 October 2023 at 17:00:41 UTC, Imperatorn wrote:


If you are having trouble using the above, try the following 
instead:

```d
dub build --compiler=ldc2 --build-mode=allAtOnce --combined
```

The complete process for dub (replace {programname} with your 
program name):

1. Specify a name and dflags
```d
	"dflags": ["-fprofile-instr-generate"],
	"name": "{programname}",
```

2. Build
```d
dub build --compiler=ldc2 --build-mode=allAtOnce --combined
```

3. Execute
```
./{programname}
```

4. Convert
```
ldc-profdata merge default.profraw -output converted.profdata
```

5. Change your dub.json to use the instrumented configuration and 
change the name
```d
	"dflags": ["-fprofile-instr-use=converted.profdata"],
	"name": "{programname}_optimized",
```

6. Build
```d
dub build --compiler=ldc2 --build-mode=allAtOnce --combined
```

7. Enjoy your PGO executable

-------------------------------------------------------------------------------------------


All the above steps in a script, but without dub, assuming app.d 
is in source

Windows:

```d
echo "Building app_normal.exe for comparison"
ldc2 -of="app_normal.exe" -O -g -gc -Isource source\app.d

echo "Building app_instrumented.exe with profiling"
ldc2 -fprofile-instr-generate -O -g -gc 
-of="app_instrumented.exe" -Isource source\app.d

echo "Running app_instrumented.exe"
app_instrumented.exe

ldc-profdata merge default.profraw -output converted.profdata

echo "Building PGO executable"
ldc2 -fprofile-instr-use=converted.profdata -O 
-of="app_optimized.exe" -Isource source\app.d -flto=full 
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto
```

*nix:

```bash
echo "Building app_normal for comparison"
ldc2 -of="app_normal" -O -g -gc -Isource source/app.d

echo "Building app_instrumented with profiling"
ldc2 -fprofile-instr-generate -O -g -gc -of="app_instrumented" 
-Isource source/app.d

echo "Running app_instrumented"
./app_instrumented

ldc-profdata merge default.profraw -output converted.profdata

echo "Building PGO executable"
ldc2 -fprofile-instr-use=converted.profdata -O 
-of="app_optimized" -Isource source/app.d -flto=full 
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto
```


More information about the Digitalmars-d mailing list