[PATCH] D85628: [HotColdSplitting] Add command line options for supplying cold function names via user input.
Ruijie Fang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 00:22:39 PDT 2020
rjf created this revision.
rjf added reviewers: hiraditya, rcorcs.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
rjf requested review of this revision.
In some cases, the user might want to specify which functions are
explicitly cold. This commit adds two options, `cold-functions-list` and
`cold-functions-file` that enables the user to supply lists of cold
function names to hot/cold splitting. The optimization pass will then
mark any function encountered with the same name as cold.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85628
Files:
llvm/lib/Transforms/IPO/HotColdSplitting.cpp
Index: llvm/lib/Transforms/IPO/HotColdSplitting.cpp
===================================================================
--- llvm/lib/Transforms/IPO/HotColdSplitting.cpp
+++ llvm/lib/Transforms/IPO/HotColdSplitting.cpp
@@ -69,6 +69,11 @@
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <algorithm>
#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <set>
+#include <sstream>
+#include <string>
#define DEBUG_TYPE "hotcoldsplit"
@@ -85,6 +90,21 @@
cl::desc("Base penalty for splitting cold code (as a "
"multiple of TCC_Basic)"));
+static cl::opt<std::string>
+ ColdFunctionsList("cold-functions-list", cl::init(""), cl::Hidden,
+ cl::desc("Comma-separated list of functions to mark"
+ " as cold during hot/cold splitting."));
+
+static cl::opt<std::string>
+ ColdFunctionsFile("cold-functions-file", cl::init(""), cl::Hidden,
+ cl::desc("File name containing a newline-separated list"
+ " of function names to mark as cold during"
+ " hot/cold splitting."));
+
+// List of cold function names to watch out
+// during optimization.
+static std::set<std::string> UserSuppliedColdFunctions;
+
namespace {
// Same as blockEndsInUnreachable in CodeGen/BranchFolding.cpp. Do not modify
// this function unless you modify the MBB version as well.
@@ -202,6 +222,12 @@
if (PSI->isFunctionEntryCold(&F))
return true;
+ // Alternatively, if user supplies any extra information
+ // on cold functions via command-line or file input,
+ // use them to determine if function is cold or not.
+ if (UserSuppliedColdFunctions.find(F.getName().str()) !=
+ UserSuppliedColdFunctions.end())
+ return true;
return false;
}
@@ -656,6 +682,32 @@
bool HotColdSplitting::run(Module &M) {
bool Changed = false;
bool HasProfileSummary = (M.getProfileSummary(/* IsCS */ false) != nullptr);
+
+ // Read in user-defined cold function names, if any.
+ if (ColdFunctionsList != "") {
+ std::stringstream CFStream(ColdFunctionsList);
+ while (CFStream.good()) {
+ std::string CFName;
+ std::getline(CFStream, CFName, ',');
+ UserSuppliedColdFunctions.insert(CFName);
+ }
+ }
+
+ // Read in user-defined cold function names supplied
+ // by a file.
+ if (ColdFunctionsFile != "") {
+ if (ColdFunctionsFile == "stdin") {
+ std::string CFName;
+ while (std::cin >> CFName)
+ UserSuppliedColdFunctions.insert(CFName);
+ } else {
+ std::fstream FromFile(ColdFunctionsFile, std::fstream::in);
+ std::string CFName;
+ while (FromFile >> CFName)
+ UserSuppliedColdFunctions.insert(CFName);
+ }
+ }
+
for (auto It = M.begin(), End = M.end(); It != End; ++It) {
Function &F = *It;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85628.284268.patch
Type: text/x-patch
Size: 2896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200810/e0d368e5/attachment.bin>
More information about the llvm-commits
mailing list