ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.21k stars 261 forks source link

Dynamic PGO #2518

Open Hardcode84 opened 6 years ago

Hardcode84 commented 6 years ago

With dynamic compilation we can switch profile info collection or usage dynamically without application recompilation (in theory).

One of the issues that LDC emit counters in function only if profiling was enabled. Instead we need to do something like this:

const bool enableProfiling = ...
void foo()
{
  if (enableProfiling ) {
    //Use counter
  }
  ..
}

and hope LLVM optimizer will remove dead code and it won't impact any optimizations. Also we don't know is function dynamic during DtoDefineFunction because some functions can be implicitly marked dynamic later.

And I don't know what additional runtime support required for PGO. @JohanEngelen what do you think?

Hardcode84 commented 6 years ago

Usage:

CompilerSettings settings;
settings.profile = true;
compileDynamicCode(settings);

//... Some profiling runs

CompilerSettings settings;
settings.pgo = true;
compileDynamicCode(settings); // Use collected profile info
JohanEngelen commented 6 years ago

hmmmmmmm Best to raise this on llvm-dev and see what people think. Compiling with IR PGO instrumentation enabled is perhaps not too hard. However, getting the profile data may be very hard. (the profile runtime startup and exit code cannot be readily used for the dyn compile case)