[PATCH] D89078: Add `-f[no-]split-cold-code` toggling outlining & enable in -O

2020-10-13 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd abandoned this revision.
compnerd added a comment.

Sure, I think I can do that instead.  Thanks for pointing me to that!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89078/new/

https://reviews.llvm.org/D89078

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89078: Add `-f[no-]split-cold-code` toggling outlining & enable in -O

2020-10-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

@compnerd thank you for working on upstreaming this patch! Would you be open to 
commandeering D57265  instead? This is my 
(unfortunately stalled) attempt to upstream the same patch, and it has some 
review concerns from Fedor Sergeev, Philip Pfaffe, and others addressed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89078/new/

https://reviews.llvm.org/D89078

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89078: Add `-f[no-]split-cold-code` toggling outlining & enable in -O

2020-10-08 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd created this revision.
compnerd added reviewers: vsk, rnk.
Herald added subscribers: llvm-commits, cfe-commits, dang, hiraditya.
Herald added projects: clang, LLVM.
compnerd requested review of this revision.

In order for the hot/cold splitting pass to graduate out of
experimental status, users need some way to safely enable it.

The current method of passing -mllvm -hot-cold-split=true to clang is
not safe, because directly setting a `cl::opt` cannot interact well with
other CC1 options (e.g. -O0, or `-disable-llvm-passes`).

This patch adds -f[no-]split-cold-code CC1 options to clang so that the
splitting pass can be toggled/combined with other options without issue.
This makes it possible to deploy the new pass on a large scale.

Patch by Vedant Kumar !

This is extracted from the patches from the Swift contributed changes to
LLVM at https://github.com/llvm/llvm-project-staging/.

The few test changes here are to allow the tests to continue working
unperturbed.

This has been shipping with the Apple toolchain and has been tested.
The known deficiencies of the outlining here are the incorrect handling
for Windows EH unwind pads which are sometimes duplicately outlined
incorrectly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89078

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/split-cold-code.c
  clang/test/CodeGenCXX/microsoft-abi-typeid.cpp
  clang/test/CodeGenCXX/nrvo.cpp
  clang/test/CodeGenObjC/synchronized.m
  clang/test/CodeGenObjCXX/exceptions-legacy.mm
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Transforms/IPO/PassManagerBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
===
--- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -194,6 +194,7 @@
 VerifyInput = false;
 VerifyOutput = false;
 MergeFunctions = false;
+SplitColdCode = false;
 PrepareForLTO = false;
 EnablePGOInstrGen = false;
 EnablePGOCSInstrGen = false;
@@ -865,7 +866,8 @@
 
   // See comment in the new PM for justification of scheduling splitting at
   // this stage (\ref buildModuleSimplificationPipeline).
-  if (EnableHotColdSplit && !(PrepareForLTO || PrepareForThinLTO))
+  if ((EnableHotColdSplit || SplitColdCode) &&
+  !(PrepareForLTO || PrepareForThinLTO))
 MPM.add(createHotColdSplittingPass());
 
   if (MergeFunctions)
@@ -1089,7 +1091,7 @@
 legacy::PassManagerBase ) {
   // See comment in the new PM for justification of scheduling splitting at
   // this stage (\ref buildLTODefaultPipeline).
-  if (EnableHotColdSplit)
+  if (EnableHotColdSplit || SplitColdCode)
 PM.add(createHotColdSplittingPass());
 
   // Delete basic blocks, which optimization passes may have killed.
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1231,7 +1231,7 @@
   // Split out cold code. Splitting is done late to avoid hiding context from
   // other optimizations and inadvertently regressing performance. The tradeoff
   // is that this has a higher code size cost than splitting early.
-  if (EnableHotColdSplit && !LTOPreLink)
+  if ((EnableHotColdSplit || SplitColdCode) && !LTOPreLink)
 MPM.addPass(HotColdSplittingPass());
 
   // LoopSink pass sinks instructions hoisted by LICM, which serves as a
@@ -1620,7 +1620,7 @@
 
   // Enable splitting late in the FullLTO post-link pipeline. This is done in
   // the same stage in the old pass manager (\ref addLateLTOOptimizationPasses).
-  if (EnableHotColdSplit)
+  if (EnableHotColdSplit || SplitColdCode)
 MPM.addPass(HotColdSplittingPass());
 
   // Add late LTO optimization passes.
@@ -2817,6 +2817,10 @@
   return Error::success();
 }
 
+void PassBuilder::setEnableHotColdSplitting(bool Enabled) {
+  SplitColdCode = Enabled;
+}
+
 bool PassBuilder::isAAPassName(StringRef PassName) {
 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS)   \
   if (PassName == NAME)\
Index: llvm/include/llvm/Transforms/IPO/PassManagerBuilder.h
===
--- llvm/include/llvm/Transforms/IPO/PassManagerBuilder.h
+++ llvm/include/llvm/Transforms/IPO/PassManagerBuilder.h
@@ -167,6 +167,7 @@
   bool VerifyInput;
   bool VerifyOutput;
   bool MergeFunctions;
+  bool SplitColdCode;
   bool PrepareForLTO;
   bool PrepareForThinLTO;
   bool PerformThinLTO;
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h