llvm.org GIT mirror llvm / 1924040
Retry^4 "[llvm-profdata] Add option to ingest filepaths from a file" Changes since the initial commit: - Use echo instead of printf. This should side-step the character escaping issues on Windows. Differential Revision: http://reviews.llvm.org/D20980 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272068 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 3 years ago
3 changed file(s) with 85 addition(s) and 6 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: echo '# comment 1' > %t.input
2 RUN: echo ' # comment 2' >> %t.input
3 RUN: echo 'bar' >> %t.input
4 RUN: echo ' baz' >> %t.input
5 RUN: echo "2,%t.weighted" >> %t.input
6
7 # Create the weighted file, since these actually need to exist.
8 RUN: echo ' ' > %t.weighted
9
10 RUN: llvm-profdata merge -f %t.input -dump-input-file-list -o /dev/null foo | FileCheck %s
11 RUN: llvm-profdata merge -input-files %t.input -dump-input-file-list -o /dev/null foo | FileCheck %s
12
13 CHECK: 1,foo
14 CHECK-NEXT: 1,bar
15 CHECK-NEXT: 1,baz
16 CHECK-NEXT: 2,{{.*}}.weighted
222222 return WeightedFile(FileName, Weight);
223223 }
224224
225 static std::unique_ptr
226 getInputFilenamesFileBuf(const StringRef &InputFilenamesFile) {
227 if (InputFilenamesFile == "")
228 return {};
229
230 auto BufOrError = MemoryBuffer::getFileOrSTDIN(InputFilenamesFile);
231 if (!BufOrError)
232 exitWithErrorCode(BufOrError.getError(), InputFilenamesFile);
233
234 return std::move(*BufOrError);
235 }
236
237 static void parseInputFilenamesFile(MemoryBuffer *Buffer,
238 WeightedFileVector &WFV) {
239 if (!Buffer)
240 return;
241
242 SmallVector Entries;
243 StringRef Data = Buffer->getBuffer();
244 Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
245 for (const StringRef &FileWeightEntry : Entries) {
246 StringRef SanitizedEntry = FileWeightEntry.trim(" \t\v\f\r");
247 // Skip comments.
248 if (SanitizedEntry.startswith("#"))
249 continue;
250 // If there's no comma, it's an unweighted profile.
251 else if (SanitizedEntry.find(',') == StringRef::npos)
252 WFV.emplace_back(SanitizedEntry, 1);
253 else
254 WFV.emplace_back(parseWeightedFile(SanitizedEntry));
255 }
256 }
257
225258 static int merge_main(int argc, const char *argv[]) {
226259 cl::list InputFilenames(cl::Positional,
227260 cl::desc(""));
228261 cl::list WeightedInputFilenames("weighted-input",
229262 cl::desc(","));
263 cl::opt InputFilenamesFile(
264 "input-files", cl::init(""),
265 cl::desc("Path to file containing newline-separated "
266 "[,] entries"));
267 cl::alias InputFilenamesFileA("f", cl::desc("Alias for --input-files"),
268 cl::aliasopt(InputFilenamesFile));
269 cl::opt DumpInputFileList(
270 "dump-input-file-list", cl::init(false), cl::Hidden,
271 cl::desc("Dump the list of input files and their weights, then exit"));
230272 cl::opt OutputFilename("output", cl::value_desc("output"),
231273 cl::init("-"), cl::Required,
232274 cl::desc("Output file"));
248290
249291 cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
250292
251 if (InputFilenames.empty() && WeightedInputFilenames.empty())
293 WeightedFileVector WeightedInputs;
294 for (StringRef Filename : InputFilenames)
295 WeightedInputs.emplace_back(Filename, 1);
296 for (StringRef WeightedFilename : WeightedInputFilenames)
297 WeightedInputs.emplace_back(parseWeightedFile(WeightedFilename));
298
299 // Make sure that the file buffer stays alive for the duration of the
300 // weighted input vector's lifetime.
301 auto Buffer = getInputFilenamesFileBuf(InputFilenamesFile);
302 parseInputFilenamesFile(Buffer.get(), WeightedInputs);
303
304 if (WeightedInputs.empty())
252305 exitWithError("No input files specified. See " +
253306 sys::path::filename(argv[0]) + " -help");
254307
255 WeightedFileVector WeightedInputs;
256 for (StringRef Filename : InputFilenames)
257 WeightedInputs.push_back(WeightedFile(Filename, 1));
258 for (StringRef WeightedFilename : WeightedInputFilenames)
259 WeightedInputs.push_back(parseWeightedFile(WeightedFilename));
308 if (DumpInputFileList) {
309 for (auto &WF : WeightedInputs)
310 outs() << WF.Weight << "," << WF.Filename << "\n";
311 return 0;
312 }
260313
261314 if (ProfileKind == instr)
262315 mergeInstrProfile(WeightedInputs, OutputFilename, OutputFormat,