This is an archive of the discontinued LLVM Phabricator instance.

[MLGO] ML Regalloc Eviction Advisor
ClosedPublic

Authored by mtrofin on Jan 12 2022, 1:51 PM.

Details

Summary

The bulk of the implementation is common between 'release' mode (==AOT-ed
model) and 'development' mode (for training), the main difference is
that in development mode, we may also log features (for training logs),
inject scoring information (currently after the Virtual Register
Rewriter) and then produce the log file.

This patch also introduces the score injection pass, 'Register
Allocation Pass Scoring', which is trivially just logging the score in
development mode.

Diff Detail

Event Timeline

mtrofin created this revision.Jan 12 2022, 1:51 PM
mtrofin requested review of this revision.Jan 12 2022, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2022, 1:51 PM
mtrofin added inline comments.Jan 12 2022, 1:53 PM
llvm/include/llvm/CodeGen/Passes.h
556

I was torn between lumping this in here and separating it out - it's simple... but then it adds like 4 additional trivial test file changes, plus the headers.

Happy to peel it off in a separate change.

yundiqian accepted this revision.Jan 18 2022, 1:11 PM
This revision is now accepted and ready to land.Jan 18 2022, 1:11 PM
This revision was landed with ongoing or failed builds.Jan 19 2022, 11:00 AM
This revision was automatically updated to reflect the committed changes.

Doesn't compile on at least one buildbot,

/work/omp-vega20-0/openmp-offload-amdgpu-runtime/llvm.src/llvm/include/llvm/PassSupport.h:46:63: error: explicit qualification in declaration of 'void llvm::initializeRegAllocScoringPass(llvm::PassRegistry&)'
   void llvm::initialize##passName##Pass(PassRegistry &Registry) {              \
                                                               ^
/work/omp-vega20-0/openmp-offload-amdgpu-runtime/llvm.src/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp:99:1: note: in expansion of macro 'INITIALIZE_PASS'
 INITIALIZE_PASS(RegAllocScoring, "regallocscoringpass",

https://lab.llvm.org/buildbot/#/builders/193/builds/4879

Also failed on an ubuntu builder:
https://lab.llvm.org/buildbot/#/builders/139/builds/16405

And passed on a debian / clang one
https://lab.llvm.org/buildbot/#/builders/109/builds/30171

Maybe builds with clang and not gcc?

ack - looking or will revert if it takes me longer

Thanks! Fixed by the above patch, https://lab.llvm.org/buildbot/#/builders/193/builds/4881 passed

Thanks for confirming, and sorry for the trouble - I did build locally before sending, no idea how it didn't break (probably dirty build dirs)

uabelho added inline comments.
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
484

Hello!
WHen compiling current trunk, 385f5c4d33, this function seems to be unused:

[482/2378] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/MLRegallocEvictAdvisor.cpp.o
../lib/CodeGen/MLRegallocEvictAdvisor.cpp:506:1: warning: '{anonymous}::MLEvictAdvisor::MLEvictAdvisor(const llvm::MachineFunction&, const llvm::RAGreedy&, llvm::MLModelRunner*, const llvm::MachineBlockFrequencyInfo&, const llvm::MachineLoopInfo&)' defined but not used [-Wunused-function]
  506 | MLEvictAdvisor::MLEvictAdvisor(const MachineFunction &MF, const RAGreedy &RA,
      | ^~~~~~~~~~~~~~

Will it be used or may it be removed?

mtrofin added inline comments.Feb 8 2022, 12:51 AM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
484

The use is under conditional compilation. If the warning is causing an issue, I can find an alternative (either wrap the def in conditional compilation, or have a default use)

uabelho added inline comments.Feb 8 2022, 12:58 AM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
484

Aha, I see.
It's not a a major issue, but we compile the codebase with gcc as well as with clang, and gcc complained about it.
But if the only use is hidden behind an ifdef maybe the function should be as well then?

mtrofin added inline comments.Feb 8 2022, 1:01 AM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
484

Ack - or I think I can have a default use. I'll address this shortly (PST here :) )

uabelho added inline comments.Feb 8 2022, 1:03 AM
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
484

Nice, thanks! No panic :)

mtrofin marked 3 inline comments as done.Feb 8 2022, 8:45 AM
mtrofin added inline comments.
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
484

Done.