llvm.org GIT mirror llvm / 4333164
Revert "Retry^2 "[llvm-profdata] Add option to ingest filepaths from a file"" This reverts commit r271953. It's still breaking on Windows, though the list initialization issue is fixed: http://bb.pgr.jp/builders/ninja-clang-i686-msc19-R/builds/3751 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271963 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 4 years ago
3 changed file(s) with 14 addition(s) and 89 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
207207 Writer->write(ProfileMap);
208208 }
209209
210 static std::string canonicalizeFilePath(StringRef Filename) {
211 SmallString<256> CanonicalFilename;
212 sys::path::native(Filename, CanonicalFilename);
213 return StringRef(CanonicalFilename).str();
214 }
215
216210 static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) {
217 StringRef WeightStr, FilenameStr;
218 std::tie(WeightStr, FilenameStr) = WeightedFilename.split(',');
211 StringRef WeightStr, FileName;
212 std::tie(WeightStr, FileName) = WeightedFilename.split(',');
219213
220214 uint64_t Weight;
221215 if (WeightStr.getAsInteger(10, Weight) || Weight < 1)
222216 exitWithError("Input weight must be a positive integer.");
223217
224 std::string CanonicalFilename = canonicalizeFilePath(FilenameStr);
225
226 if (!sys::fs::exists(CanonicalFilename))
218 if (!sys::fs::exists(FileName))
227219 exitWithErrorCode(make_error_code(errc::no_such_file_or_directory),
228 CanonicalFilename);
229
230 return WeightedFile(StringRef(CanonicalFilename).str(), Weight);
231 }
232
233 static void parseInputFilenamesFile(const StringRef &InputFilenamesFile,
234 WeightedFileVector &WFV) {
235 if (InputFilenamesFile == "")
236 return;
237
238 auto BufOrError = MemoryBuffer::getFileOrSTDIN(InputFilenamesFile);
239 if (!BufOrError)
240 exitWithErrorCode(BufOrError.getError(), InputFilenamesFile);
241
242 auto Buffer = std::move(*BufOrError);
243 StringRef Data = Buffer->getBuffer();
244 SmallVector Entries;
245 Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
246 for (const StringRef &FileWeightEntry : Entries) {
247 StringRef SanitizedEntry = FileWeightEntry.trim(" \t\v\f\r");
248 // Skip comments.
249 if (SanitizedEntry.startswith("#"))
250 continue;
251 // If there's no comma, it's an unweighted profile.
252 else if (SanitizedEntry.find(',') == StringRef::npos)
253 WFV.emplace_back(canonicalizeFilePath(SanitizedEntry), 1);
254 else
255 WFV.emplace_back(parseWeightedFile(SanitizedEntry));
256 }
220 FileName);
221
222 return WeightedFile(FileName, Weight);
257223 }
258224
259225 static int merge_main(int argc, const char *argv[]) {
261227 cl::desc(""));
262228 cl::list WeightedInputFilenames("weighted-input",
263229 cl::desc(","));
264 cl::opt InputFilenamesFile(
265 "input-files", cl::init(""),
266 cl::desc("Path to file containing newline-separated "
267 "[,] entries"));
268 cl::alias InputFilenamesFileA("f", cl::desc("Alias for --input-files"),
269 cl::aliasopt(InputFilenamesFile));
270 cl::opt DumpInputFileList(
271 "dump-input-file-list", cl::init(false), cl::Hidden,
272 cl::desc("Dump the list of input files and their weights, then exit"));
273230 cl::opt OutputFilename("output", cl::value_desc("output"),
274231 cl::init("-"), cl::Required,
275232 cl::desc("Output file"));
291248
292249 cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
293250
251 if (InputFilenames.empty() && WeightedInputFilenames.empty())
252 exitWithError("No input files specified. See " +
253 sys::path::filename(argv[0]) + " -help");
254
294255 WeightedFileVector WeightedInputs;
295256 for (StringRef Filename : InputFilenames)
296 WeightedInputs.emplace_back(canonicalizeFilePath(Filename), 1);
257 WeightedInputs.push_back(WeightedFile(Filename, 1));
297258 for (StringRef WeightedFilename : WeightedInputFilenames)
298 WeightedInputs.emplace_back(parseWeightedFile(WeightedFilename));
299 parseInputFilenamesFile(InputFilenamesFile, WeightedInputs);
300
301 if (WeightedInputs.empty())
302 exitWithError("No input files specified. See " +
303 sys::path::filename(argv[0]) + " -help");
304
305 if (DumpInputFileList) {
306 for (auto &WF : WeightedInputs)
307 outs() << WF.Weight << "," << WF.Filename << "\n";
308 return 0;
309 }
259 WeightedInputs.push_back(parseWeightedFile(WeightedFilename));
310260
311261 if (ProfileKind == instr)
312262 mergeInstrProfile(WeightedInputs, OutputFilename, OutputFormat,