summaryrefslogtreecommitdiff
path: root/tools/llvm-profdata
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-06-03 19:05:20 +0000
committerVedant Kumar <vsk@apple.com>2016-06-03 19:05:20 +0000
commitc80b40eaea92ac7047d0bd73628a6f02151aed48 (patch)
tree141a1f2fe8a0d2a668fdfc752a98e156080f04e9 /tools/llvm-profdata
parentf0704e634ff102e5e7a02f63d00e2723268af08b (diff)
[llvm-profdata] Add option to ingest filepaths from a file
Differential Revision: http://reviews.llvm.org/D20980 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271709 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-profdata')
-rw-r--r--tools/llvm-profdata/llvm-profdata.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/tools/llvm-profdata/llvm-profdata.cpp b/tools/llvm-profdata/llvm-profdata.cpp
index 20a167226a3..4c3ff83d4bd 100644
--- a/tools/llvm-profdata/llvm-profdata.cpp
+++ b/tools/llvm-profdata/llvm-profdata.cpp
@@ -223,11 +223,45 @@ static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) {
return WeightedFile(FileName, Weight);
}
+static void parseInputFilenamesFile(const StringRef &InputFilenamesFile,
+ WeightedFileVector &WFV) {
+ if (InputFilenamesFile == "")
+ return;
+
+ auto Buf = MemoryBuffer::getFileOrSTDIN(InputFilenamesFile);
+ if (!Buf)
+ exitWithErrorCode(Buf.getError(), InputFilenamesFile);
+
+ StringRef Data = Buf.get()->getBuffer();
+ SmallVector<StringRef, 8> Entries;
+ 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.rfind(',') == 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 "
+ "<filename>[,<weight>] 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"));
@@ -249,15 +283,22 @@ static int merge_main(int argc, const char *argv[]) {
cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
- if (InputFilenames.empty() && WeightedInputFilenames.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));
+ parseInputFilenamesFile(InputFilenamesFile, WeightedInputs);
+
+ if (WeightedInputs.empty())
+ exitWithError("No input files specified. See " +
+ sys::path::filename(argv[0]) + " -help");
+
+ if (DumpInputFileList) {
+ for (auto &WF : WeightedInputs)
+ outs() << WF.Weight << "," << WF.Filename << "\n";
+ return 0;
+ }
if (ProfileKind == instr)
mergeInstrProfile(WeightedInputs, OutputFilename, OutputFormat,