llvm.org GIT mirror llvm / acd5f5a
Revert "Retry "[llvm-profdata] Add option to ingest filepaths from a file" This reverts commit r271949. It breaks the Windows build: http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/12796 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271952 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 3 years ago
3 changed file(s) with 14 addition(s) and 84 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 RUN: printf '# comment 1\n' > %t
1 RUN: printf ' # comment 2\n' >> %t
2
3 RUN: printf 'bar\n' >> %t
4 RUN: printf ' baz\n' >> %t
5
6 RUN: printf '2,%t.weighted\n' >> %t
7 RUN: printf ' ' > %t.weighted
8
9 RUN: llvm-profdata merge -input-files %t -dump-input-file-list foo -o /dev/null | FileCheck %s
10 RUN: llvm-profdata merge -f %t -dump-input-file-list foo -o /dev/null | FileCheck %s
11
12 CHECK: 1,foo
13 CHECK-NEXT: 1,bar
14 CHECK-NEXT: 1,baz
15 CHECK-NEXT: 2,{{.*}}.weighted
107107 }
108108
109109 struct WeightedFile {
110 std::string Filename;
110 StringRef Filename;
111111 uint64_t Weight;
112112
113113 WeightedFile() {}
114114
115 WeightedFile(std::string F, uint64_t W) : Filename{F}, Weight{W} {}
115 WeightedFile(StringRef F, uint64_t W) : Filename{F}, Weight{W} {}
116116 };
117117 typedef SmallVector WeightedFileVector;
118118
208208 }
209209
210210 static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) {
211 StringRef WeightStr, FilenameStr;
212 std::tie(WeightStr, FilenameStr) = WeightedFilename.split(',');
211 StringRef WeightStr, FileName;
212 std::tie(WeightStr, FileName) = WeightedFilename.split(',');
213213
214214 uint64_t Weight;
215215 if (WeightStr.getAsInteger(10, Weight) || Weight < 1)
216216 exitWithError("Input weight must be a positive integer.");
217217
218 SmallString<256> CanonicalFilename;
219 sys::path::native(FilenameStr, CanonicalFilename);
220
221 if (!sys::fs::exists(CanonicalFilename))
218 if (!sys::fs::exists(FileName))
222219 exitWithErrorCode(make_error_code(errc::no_such_file_or_directory),
223 CanonicalFilename);
224
225 return WeightedFile(StringRef(CanonicalFilename).str(), Weight);
226 }
227
228 static void parseInputFilenamesFile(const StringRef &InputFilenamesFile,
229 WeightedFileVector &WFV) {
230 if (InputFilenamesFile == "")
231 return;
232
233 auto BufOrError = MemoryBuffer::getFileOrSTDIN(InputFilenamesFile);
234 if (!BufOrError)
235 exitWithErrorCode(BufOrError.getError(), InputFilenamesFile);
236
237 auto Buffer = std::move(*BufOrError);
238 StringRef Data = Buffer->getBuffer();
239 SmallVector Entries;
240 Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
241 for (const StringRef &FileWeightEntry : Entries) {
242 StringRef SanitizedEntry = FileWeightEntry.trim(" \t\v\f\r");
243 // Skip comments.
244 if (SanitizedEntry.startswith("#"))
245 continue;
246 // If there's no comma, it's an unweighted profile.
247 else if (SanitizedEntry.rfind(',') == StringRef::npos)
248 WFV.emplace_back(SanitizedEntry, 1);
249 else
250 WFV.emplace_back(parseWeightedFile(SanitizedEntry));
251 }
220 FileName);
221
222 return WeightedFile(FileName, Weight);
252223 }
253224
254225 static int merge_main(int argc, const char *argv[]) {
256227 cl::desc(""));
257228 cl::list WeightedInputFilenames("weighted-input",
258229 cl::desc(","));
259 cl::opt InputFilenamesFile(
260 "input-files", cl::init(""),
261 cl::desc("Path to file containing newline-separated "
262 "[,] entries"));
263 cl::alias InputFilenamesFileA("f", cl::desc("Alias for --input-files"),
264 cl::aliasopt(InputFilenamesFile));
265 cl::opt DumpInputFileList(
266 "dump-input-file-list", cl::init(false), cl::Hidden,
267 cl::desc("Dump the list of input files and their weights, then exit"));
268230 cl::opt OutputFilename("output", cl::value_desc("output"),
269231 cl::init("-"), cl::Required,
270232 cl::desc("Output file"));
286248
287249 cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
288250
251 if (InputFilenames.empty() && WeightedInputFilenames.empty())
252 exitWithError("No input files specified. See " +
253 sys::path::filename(argv[0]) + " -help");
254
289255 WeightedFileVector WeightedInputs;
290256 for (StringRef Filename : InputFilenames)
291 WeightedInputs.emplace_back(Filename, 1);
257 WeightedInputs.push_back(WeightedFile(Filename, 1));
292258 for (StringRef WeightedFilename : WeightedInputFilenames)
293 WeightedInputs.emplace_back(parseWeightedFile(WeightedFilename));
294 parseInputFilenamesFile(InputFilenamesFile, WeightedInputs);
295
296 if (WeightedInputs.empty())
297 exitWithError("No input files specified. See " +
298 sys::path::filename(argv[0]) + " -help");
299
300 if (DumpInputFileList) {
301 for (auto &WF : WeightedInputs)
302 outs() << WF.Weight << "," << WF.Filename << "\n";
303 return 0;
304 }
259 WeightedInputs.push_back(parseWeightedFile(WeightedFilename));
305260
306261 if (ProfileKind == instr)
307262 mergeInstrProfile(WeightedInputs, OutputFilename, OutputFormat,