llvm.org GIT mirror llvm / c80b40e
[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 Vedant Kumar 3 years ago
3 changed file(s) with 70 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
4343 nature of the training runs it may be useful to adjust the weight given to each
4444 input file by using the ``-weighted-input`` option.
4545
46 Profiles passed in via ``-weighted-input``, ``-input-files``, or via positional
47 arguments are processed once for each time they are seen.
48
4649
4750 OPTIONS
4851 ^^^^^^^
6366 ``weight``, where where ``weight`` is a decimal integer >= 1.
6467 Input files specified without using this option are assigned a default
6568 weight of 1. Examples are shown below.
69
70 .. option:: -input-files=path, -f=path
71
72 Specify a file which contains a list of files to merge. The entries in this
73 file are newline-separated. Lines starting with '#' are skipped. Entries may
74 be of the form or ,.
6675
6776 .. option:: -instr (default)
6877
0 # Create an input file.
1 RUN: printf '# comment 1\n' > %t.input
2 RUN: printf ' # comment 2\n' >> %t.input
3 RUN: printf 'foo\n' >> %t.input
4 RUN: printf ' bar\n' >> %t.input
5 RUN: printf "2,%t.weighted\n" >> %t.input
6
7 # Create the weighted file, since these actually need to exist.
8 RUN: printf ' ' > %t.weighted
9
10 # RUN: llvm-profdata merge -f %t.input -dump-input-file-list -o /dev/null | FileCheck %s
11 # RUN: llvm-profdata merge -input-files %t.input -dump-input-file-list -o /dev/null | FileCheck %s
12
13 # CHECK: 1,foo
14 # CHECK-NEXT: 1,bar
15 # CHECK-NEXT: 2,{{.*}}.weighted
222222 return WeightedFile(FileName, Weight);
223223 }
224224
225 static void parseInputFilenamesFile(const StringRef &InputFilenamesFile,
226 WeightedFileVector &WFV) {
227 if (InputFilenamesFile == "")
228 return;
229
230 auto Buf = MemoryBuffer::getFileOrSTDIN(InputFilenamesFile);
231 if (!Buf)
232 exitWithErrorCode(Buf.getError(), InputFilenamesFile);
233
234 StringRef Data = Buf.get()->getBuffer();
235 SmallVector Entries;
236 Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
237 for (const StringRef &FileWeightEntry : Entries) {
238 StringRef SanitizedEntry = FileWeightEntry.trim(" \t\v\f\r");
239 // Skip comments.
240 if (SanitizedEntry.startswith("#"))
241 continue;
242 // If there's no comma, it's an unweighted profile.
243 else if (SanitizedEntry.rfind(',') == StringRef::npos)
244 WFV.emplace_back(SanitizedEntry, 1);
245 else
246 WFV.emplace_back(parseWeightedFile(SanitizedEntry));
247 }
248 }
249
225250 static int merge_main(int argc, const char *argv[]) {
226251 cl::list InputFilenames(cl::Positional,
227252 cl::desc(""));
228253 cl::list WeightedInputFilenames("weighted-input",
229254 cl::desc(","));
255 cl::opt InputFilenamesFile(
256 "input-files", cl::init(""),
257 cl::desc("Path to file containing newline-separated "
258 "[,] entries"));
259 cl::alias InputFilenamesFileA("f", cl::desc("Alias for --input-files"),
260 cl::aliasopt(InputFilenamesFile));
261 cl::opt DumpInputFileList(
262 "dump-input-file-list", cl::init(false), cl::Hidden,
263 cl::desc("Dump the list of input files and their weights, then exit"));
230264 cl::opt OutputFilename("output", cl::value_desc("output"),
231265 cl::init("-"), cl::Required,
232266 cl::desc("Output file"));
248282
249283 cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
250284
251 if (InputFilenames.empty() && WeightedInputFilenames.empty())
252 exitWithError("No input files specified. See " +
253 sys::path::filename(argv[0]) + " -help");
254
255285 WeightedFileVector WeightedInputs;
256286 for (StringRef Filename : InputFilenames)
257287 WeightedInputs.push_back(WeightedFile(Filename, 1));
258288 for (StringRef WeightedFilename : WeightedInputFilenames)
259289 WeightedInputs.push_back(parseWeightedFile(WeightedFilename));
290 parseInputFilenamesFile(InputFilenamesFile, WeightedInputs);
291
292 if (WeightedInputs.empty())
293 exitWithError("No input files specified. See " +
294 sys::path::filename(argv[0]) + " -help");
295
296 if (DumpInputFileList) {
297 for (auto &WF : WeightedInputs)
298 outs() << WF.Weight << "," << WF.Filename << "\n";
299 return 0;
300 }
260301
261302 if (ProfileKind == instr)
262303 mergeInstrProfile(WeightedInputs, OutputFilename, OutputFormat,