[PATCH] D77752: [llvm] Machine Learned policy for inlining -Oz

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 8 14:08:35 PDT 2020


mtrofin created this revision.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, mgrang, haicheng, hiraditya, eraman, mgorny.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a project: LLVM.
mtrofin edited the summary of this revision.

[llvm] Machine Learned policy for inlining -Oz

**This change is meant to be subsequently split into smaller changes. For now, it offers an overview of the overall proposal.**

Please refer to the RFC for more details <http://lists.llvm.org/pipermail/llvm-dev/2020-April/140763.html>.

The change introduces a machine learned policy for -Oz inlining as a build-time opt-in.

There are two opt-in modes: relese("rel") and development ("dev").

**'Release'** is the 'normal compiler use'. A pre-trained ML model is compiled ahead of time into a native library, which is then used to make inlining
decisions. Determinism is ensured because the model is unchanged as the compiler runs.

Just like with hand-written heuristics, there is no formal guarantee that the policy performs well, only empirical results on benchmarks, based on which we derive a belief of general applicability.

**'Development'** is the mode used to train a model. Training happens offline, through reinforcement learning, by providing a training algorithm with traces of decisions made by the compiler on a training corpus (IR modules).

This initial change introduces all the 'release' mode components, together with a reference, pre-trained model, as well as key training mode components. More training mode components will be provided in subsequent changes. The reference model was trained on a Google-internal corpus of ~25K IR modules, and appears to generalize well to clang, opt, SPEC2006 (which are code bases sharing little to nothing with the training corpus), as well as some internal binaries. We observe as much as 6% size reduction (opt), and generally ~3%, when compared to clang -Oz.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77752

Files:
  llvm/CMakeLists.txt
  llvm/cmake/modules/TensorFlowCompile.cmake
  llvm/include/llvm/Analysis/InlineCost.h
  llvm/include/llvm/Analysis/ML/IRToNativeSizeLearning.h
  llvm/include/llvm/Analysis/ML/InliningAdvisor.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Transforms/IPO/Inliner.h
  llvm/lib/Analysis/CMakeLists.txt
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/Analysis/InliningAdvisor.cpp
  llvm/lib/Analysis/ML/CMakeLists.txt
  llvm/lib/Analysis/ML/IRToNativeSizeLearning.cpp
  llvm/lib/Analysis/ML/InliningAdvisor.cpp
  llvm/lib/Analysis/ML/InliningModelFeatureMaps.h
  llvm/lib/Analysis/ML/InliningModelRunnerProduction.h
  llvm/lib/Analysis/ML/InliningModelRunnerTraining.h
  llvm/lib/Analysis/ML/TFUtils.cpp
  llvm/lib/Analysis/ML/TFUtils.h
  llvm/lib/Analysis/ML/models/inliner/saved_model.pb
  llvm/lib/Analysis/ML/models/ir_to_native_x86_64/saved_model.pb
  llvm/lib/CMakeLists.txt
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/CMakeLists.txt
  llvm/lib/Transforms/IPO/Inliner.cpp
  llvm/test/Bindings/Go/lit.local.cfg
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
  llvm/test/Transforms/Inline/ML/Inputs/inliner/saved_model.pb
  llvm/test/Transforms/Inline/ML/Inputs/ir_to_native/saved_model.pb
  llvm/test/Transforms/Inline/ML/ensure-delete.ll
  llvm/test/Transforms/Inline/ML/func-features.ll
  llvm/test/Transforms/Inline/ML/graph-structure.ll
  llvm/test/Transforms/Inline/ML/lit.local.cfg.py
  llvm/test/Transforms/Inline/ML/mandatory-first.ll
  llvm/test/lit.site.cfg.py.in

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77752.256104.patch
Type: text/x-patch
Size: 109622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200408/cb827a40/attachment-0001.bin>


More information about the llvm-commits mailing list