llvm.org GIT mirror llvm / 557c624
[llvm-profdata] Revert r271709 and the 3 subsequent commits - the code and/or tests aren't working on Windows currently. There seems to be some problem with quoting the file paths. I don't understand the test structure here or the code well enough to try to come up with a way to correctly handle paths with back slashes in them, and this has caused the Windows builds to be failing for 7 hours now, so I'm reverting the whole thing to bring them back to life. Sorry for the disruption, but a couple of these were bug fixes anyways that can be folded into a fresh commit. Reverts the following patches: r271756: Clean up the way we create the input filenames buffer (NFC) r271748: Fix use-after-free from discarded MemoryBuffer (NFC) r271710: Fix option description (NFC) r271709: Add option to ingest filepaths from a file git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271760 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 3 years ago
3 changed file(s) with 4 addition(s) and 82 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
4946
5047 OPTIONS
5148 ^^^^^^^
6663 ``weight``, where where ``weight`` is a decimal integer >= 1.
6764 Input files specified without using this option are assigned a default
6865 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 ,.
7566
7667 .. option:: -instr (default)
7768
+0
-16
test/tools/llvm-profdata/input-filenames.test less more
None # 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 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.rfind(',') == StringRef::npos)
252 WFV.emplace_back(SanitizedEntry, 1);
253 else
254 WFV.emplace_back(parseWeightedFile(SanitizedEntry));
255 }
256 }
257
258225 static int merge_main(int argc, const char *argv[]) {
259226 cl::list InputFilenames(cl::Positional,
260227 cl::desc(""));
261228 cl::list WeightedInputFilenames("weighted-input",
262229 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"));
272230 cl::opt OutputFilename("output", cl::value_desc("output"),
273231 cl::init("-"), cl::Required,
274232 cl::desc("Output file"));
290248
291249 cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
292250
251 if (InputFilenames.empty() && WeightedInputFilenames.empty())
252 exitWithError("No input files specified. See " +
253 sys::path::filename(argv[0]) + " -help");
254
293255 WeightedFileVector WeightedInputs;
294256 for (StringRef Filename : InputFilenames)
295257 WeightedInputs.push_back(WeightedFile(Filename, 1));
296258 for (StringRef WeightedFilename : WeightedInputFilenames)
297259 WeightedInputs.push_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())
305 exitWithError("No input files specified. See " +
306 sys::path::filename(argv[0]) + " -help");
307
308 if (DumpInputFileList) {
309 for (auto &WF : WeightedInputs)
310 outs() << WF.Weight << "," << WF.Filename << "\n";
311 return 0;
312 }
313260
314261 if (ProfileKind == instr)
315262 mergeInstrProfile(WeightedInputs, OutputFilename, OutputFormat,