diff --git a/llvm/include/llvm/Transforms/Utils/SizeOpts.h b/llvm/include/llvm/Transforms/Utils/SizeOpts.h --- a/llvm/include/llvm/Transforms/Utils/SizeOpts.h +++ b/llvm/include/llvm/Transforms/Utils/SizeOpts.h @@ -21,6 +21,7 @@ extern cl::opt EnablePGSO; extern cl::opt PGSOLargeWorkingSetSizeOnly; +extern cl::opt PGSOColdCodeOnly; extern cl::opt ForcePGSO; extern cl::opt PgsoCutoffInstrProf; extern cl::opt PgsoCutoffSampleProf; @@ -42,7 +43,8 @@ return true; if (!EnablePGSO) return false; - if (PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize()) { + if (PGSOColdCodeOnly || + (PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize())) { // Even if the working set size isn't large, size-optimize cold code. return AdapterT::isFunctionColdInCallGraph(F, PSI, *BFI); } @@ -61,7 +63,8 @@ return true; if (!EnablePGSO) return false; - if (PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize()) { + if (PGSOColdCodeOnly || + (PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize())) { // Even if the working set size isn't large, size-optimize cold code. return AdapterT::isColdBlock(BB, PSI, BFI); } diff --git a/llvm/lib/Transforms/Utils/SizeOpts.cpp b/llvm/lib/Transforms/Utils/SizeOpts.cpp --- a/llvm/lib/Transforms/Utils/SizeOpts.cpp +++ b/llvm/lib/Transforms/Utils/SizeOpts.cpp @@ -23,6 +23,11 @@ cl::desc("Apply the profile guided size optimizations only " "if the working set size is large (except for cold code.)")); +cl::opt PGSOColdCodeOnly( + "pgso-cold-code-only", cl::Hidden, cl::init(true), + cl::desc("Apply the profile guided size optimizations only " + "to cold code.")); + cl::opt ForcePGSO( "force-pgso", cl::Hidden, cl::init(false), cl::desc("Force the (profiled-guided) size optimizations. "));