diff --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp --- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -69,6 +69,11 @@ #include "llvm/Transforms/Utils/ValueMapper.h" #include #include +#include +#include +#include +#include +#include #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 + 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 + 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 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;