[PGO] Update ldc-profdata-3.9 and profile-rt-39 to svn r273081

This commit is contained in:
Johan Engelen 2016-06-20 17:39:46 +02:00
parent 176961f325
commit 21c2c6dd4b
14 changed files with 723 additions and 198 deletions

View file

@ -223,11 +223,53 @@ static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) {
return WeightedFile(FileName, Weight);
}
static std::unique_ptr<MemoryBuffer>
getInputFilenamesFileBuf(const StringRef &InputFilenamesFile) {
if (InputFilenamesFile == "")
return {};
auto BufOrError = MemoryBuffer::getFileOrSTDIN(InputFilenamesFile);
if (!BufOrError)
exitWithErrorCode(BufOrError.getError(), InputFilenamesFile);
return std::move(*BufOrError);
}
static void parseInputFilenamesFile(MemoryBuffer *Buffer,
WeightedFileVector &WFV) {
if (!Buffer)
return;
SmallVector<StringRef, 8> Entries;
StringRef Data = Buffer->getBuffer();
Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
for (const StringRef &FileWeightEntry : Entries) {
StringRef SanitizedEntry = FileWeightEntry.trim(" \t\v\f\r");
// Skip comments.
if (SanitizedEntry.startswith("#"))
continue;
// If there's no comma, it's an unweighted profile.
else if (SanitizedEntry.find(',') == StringRef::npos)
WFV.emplace_back(SanitizedEntry, 1);
else
WFV.emplace_back(parseWeightedFile(SanitizedEntry));
}
}
static int merge_main(int argc, const char *argv[]) {
cl::list<std::string> InputFilenames(cl::Positional,
cl::desc("<filename...>"));
cl::list<std::string> WeightedInputFilenames("weighted-input",
cl::desc("<weight>,<filename>"));
cl::opt<std::string> InputFilenamesFile(
"input-files", cl::init(""),
cl::desc("Path to file containing newline-separated "
"[<weight>,]<filename> entries"));
cl::alias InputFilenamesFileA("f", cl::desc("Alias for --input-files"),
cl::aliasopt(InputFilenamesFile));
cl::opt<bool> DumpInputFileList(
"dump-input-file-list", cl::init(false), cl::Hidden,
cl::desc("Dump the list of input files and their weights, then exit"));
cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
cl::init("-"), cl::Required,
cl::desc("Output file"));
@ -237,7 +279,6 @@ static int merge_main(int argc, const char *argv[]) {
cl::desc("Profile kind:"), cl::init(instr),
cl::values(clEnumVal(instr, "Instrumentation profile (default)"),
clEnumVal(sample, "Sample profile"), clEnumValEnd));
cl::opt<ProfileFormat> OutputFormat(
cl::desc("Format of output profile"), cl::init(PF_Binary),
cl::values(clEnumValN(PF_Binary, "binary", "Binary encoding (default)"),
@ -245,21 +286,31 @@ static int merge_main(int argc, const char *argv[]) {
clEnumValN(PF_GCC, "gcc",
"GCC encoding (only meaningful for -sample)"),
clEnumValEnd));
cl::opt<bool> OutputSparse("sparse", cl::init(false),
cl::desc("Generate a sparse profile (only meaningful for -instr)"));
cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
if (InputFilenames.empty() && WeightedInputFilenames.empty())
WeightedFileVector WeightedInputs;
for (StringRef Filename : InputFilenames)
WeightedInputs.emplace_back(Filename, 1);
for (StringRef WeightedFilename : WeightedInputFilenames)
WeightedInputs.emplace_back(parseWeightedFile(WeightedFilename));
// Make sure that the file buffer stays alive for the duration of the
// weighted input vector's lifetime.
auto Buffer = getInputFilenamesFileBuf(InputFilenamesFile);
parseInputFilenamesFile(Buffer.get(), WeightedInputs);
if (WeightedInputs.empty())
exitWithError("No input files specified. See " +
sys::path::filename(argv[0]) + " -help");
WeightedFileVector WeightedInputs;
for (StringRef Filename : InputFilenames)
WeightedInputs.push_back(WeightedFile(Filename, 1));
for (StringRef WeightedFilename : WeightedInputFilenames)
WeightedInputs.push_back(parseWeightedFile(WeightedFilename));
if (DumpInputFileList) {
for (auto &WF : WeightedInputs)
outs() << WF.Weight << "," << WF.Filename << "\n";
return 0;
}
if (ProfileKind == instr)
mergeInstrProfile(WeightedInputs, OutputFilename, OutputFormat,
@ -270,24 +321,28 @@ static int merge_main(int argc, const char *argv[]) {
return 0;
}
static int showInstrProfile(std::string Filename, bool ShowCounts,
static int showInstrProfile(const std::string &Filename, bool ShowCounts,
bool ShowIndirectCallTargets,
bool ShowDetailedSummary,
std::vector<uint32_t> DetailedSummaryCutoffs,
bool ShowAllFunctions, std::string ShowFunction,
bool TextFormat, raw_fd_ostream &OS) {
bool ShowAllFunctions,
const std::string &ShowFunction, bool TextFormat,
raw_fd_ostream &OS) {
auto ReaderOrErr = InstrProfReader::create(Filename);
std::vector<uint32_t> Cutoffs(DetailedSummaryCutoffs);
if (ShowDetailedSummary && DetailedSummaryCutoffs.empty()) {
std::vector<uint32_t> Cutoffs = std::move(DetailedSummaryCutoffs);
if (ShowDetailedSummary && Cutoffs.empty()) {
Cutoffs = {800000, 900000, 950000, 990000, 999000, 999900, 999990};
}
InstrProfSummaryBuilder Builder(Cutoffs);
InstrProfSummaryBuilder Builder(std::move(Cutoffs));
if (Error E = ReaderOrErr.takeError())
exitWithError(std::move(E), Filename);
auto Reader = std::move(ReaderOrErr.get());
bool IsIRInstr = Reader->isIRLevelProfile();
size_t ShownFunctions = 0;
uint64_t TotalNumValueSites = 0;
uint64_t TotalNumValueSitesWithValueProfile = 0;
uint64_t TotalNumValues = 0;
for (const auto &Func : *Reader) {
bool Show =
ShowAllFunctions || (!ShowFunction.empty() &&
@ -334,10 +389,14 @@ static int showInstrProfile(std::string Filename, bool ShowCounts,
InstrProfSymtab &Symtab = Reader->getSymtab();
uint32_t NS = Func.getNumValueSites(IPVK_IndirectCallTarget);
OS << " Indirect Target Results: \n";
TotalNumValueSites += NS;
for (size_t I = 0; I < NS; ++I) {
uint32_t NV = Func.getNumValueDataForSite(IPVK_IndirectCallTarget, I);
std::unique_ptr<InstrProfValueData[]> VD =
Func.getValueForSite(IPVK_IndirectCallTarget, I);
TotalNumValues += NV;
if (NV)
TotalNumValueSitesWithValueProfile++;
for (uint32_t V = 0; V < NV; V++) {
OS << "\t[ " << I << ", ";
OS << Symtab.getFuncName(VD[V].Value) << ", " << VD[V].Count
@ -347,7 +406,6 @@ static int showInstrProfile(std::string Filename, bool ShowCounts,
}
}
}
if (Reader->hasError())
exitWithError(Reader->getError(), Filename);
@ -359,6 +417,13 @@ static int showInstrProfile(std::string Filename, bool ShowCounts,
OS << "Total functions: " << PS->getNumFunctions() << "\n";
OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n";
OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n";
if (ShownFunctions && ShowIndirectCallTargets) {
OS << "Total Number of Indirect Call Sites : " << TotalNumValueSites
<< "\n";
OS << "Total Number of Sites With Values : "
<< TotalNumValueSitesWithValueProfile << "\n";
OS << "Total Number of Profiled Values : " << TotalNumValues << "\n";
}
if (ShowDetailedSummary) {
OS << "Detailed summary:\n";
@ -374,8 +439,9 @@ static int showInstrProfile(std::string Filename, bool ShowCounts,
return 0;
}
static int showSampleProfile(std::string Filename, bool ShowCounts,
bool ShowAllFunctions, std::string ShowFunction,
static int showSampleProfile(const std::string &Filename, bool ShowCounts,
bool ShowAllFunctions,
const std::string &ShowFunction,
raw_fd_ostream &OS) {
using namespace sampleprof;
LLVMContext Context;
@ -454,7 +520,7 @@ static int show_main(int argc, const char *argv[]) {
int main(int argc, const char *argv[]) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.