llvm.org GIT mirror llvm / 30a3883
Reapply r276185 Fix the test case that should not depend on dir iteration order. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276197 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 3 years ago
3 changed file(s) with 65 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
0 # Create an input file.
1 RUN: echo "#" > %t.input
2 RUN: echo "%t.dir1" >> %t.input
3 RUN: echo "2,%t.dir2" >> %t.input
4
5 RUN: mkdir -p %t.dir1
6 RUN: mkdir -p %t.dir2/subdir
7
8 RUN: echo ' ' > %t.dir1/bar
9 RUN: echo ' ' > %t.dir1/foo
10 RUN: echo ' ' > %t.dir2/bar
11 RUN: echo ' ' > %t.dir2/foo
12 RUN: echo ' ' > %t.dir2/subdir/baz
13
14 RUN: llvm-profdata merge -f %t.input -dump-input-file-list -o /dev/null | FileCheck %s
15 RUN: llvm-profdata merge -weighted-input=2,%t.dir2 -dump-input-file-list -o /dev/null %t.dir1 | FileCheck %s
16
17 CHECK-DAG: 1,{{.*}}.dir1/bar
18 CHECK-DAG: 1,{{.*}}.dir1/foo
19 CHECK-DAG: 2,{{.*}}.dir2/bar
20 CHECK-DAG: 2,{{.*}}.dir2/foo
21 CHECK-DAG: 2,{{.*}}.dir2/subdir/baz
0 # Create an input file.
11 RUN: echo '# comment 1' > %t.input
22 RUN: echo ' # comment 2' >> %t.input
3 RUN: echo 'bar' >> %t.input
4 RUN: echo ' baz' >> %t.input
3 RUN: echo " %t.bar" >> %t.input
4 RUN: echo " %t.baz" >> %t.input
55 RUN: echo "2,%t.weighted" >> %t.input
66
7 # Create the weighted file, since these actually need to exist.
87 RUN: echo ' ' > %t.weighted
8 RUN: echo ' ' > %t.foo
9 RUN: echo ' ' > %t.bar
10 RUN: echo ' ' > %t.baz
911
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 RUN: llvm-profdata merge -f %t.input -dump-input-file-list -o /dev/null %t.foo | FileCheck %s
13 RUN: llvm-profdata merge -input-files %t.input -dump-input-file-list -o /dev/null %t.foo | FileCheck %s
1214
13 CHECK: 1,foo
14 CHECK-NEXT: 1,bar
15 CHECK-NEXT: 1,baz
15 CHECK: 1,{{.*}}.foo
16 CHECK-NEXT: 1,{{.*}}.bar
17 CHECK-NEXT: 1,{{.*}}.baz
1618 CHECK-NEXT: 2,{{.*}}.weighted
108108 }
109109
110110 struct WeightedFile {
111 StringRef Filename;
111 std::string Filename;
112112 uint64_t Weight;
113113
114114 WeightedFile() {}
115115
116 WeightedFile(StringRef F, uint64_t W) : Filename{F}, Weight{W} {}
116 WeightedFile(const std::string &F, uint64_t W) : Filename{F}, Weight{W} {}
117117 };
118118 typedef SmallVector WeightedFileVector;
119119
304304 if (WeightStr.getAsInteger(10, Weight) || Weight < 1)
305305 exitWithError("Input weight must be a positive integer.");
306306
307 if (!sys::fs::exists(FileName))
308 exitWithErrorCode(make_error_code(errc::no_such_file_or_directory),
309 FileName);
310
311307 return WeightedFile(FileName, Weight);
312308 }
313309
321317 exitWithErrorCode(BufOrError.getError(), InputFilenamesFile);
322318
323319 return std::move(*BufOrError);
320 }
321
322 static void addWeightedInput(WeightedFileVector &WNI, const WeightedFile &WF) {
323 StringRef Filename = WF.Filename;
324 uint64_t Weight = WF.Weight;
325 llvm::sys::fs::file_status Status;
326 llvm::sys::fs::status(Filename, Status);
327 if (!llvm::sys::fs::exists(Status))
328 exitWithErrorCode(make_error_code(errc::no_such_file_or_directory),
329 Filename);
330 // If it's a source file, collect it.
331 if (llvm::sys::fs::is_regular_file(Status)) {
332 WNI.emplace_back(Filename, Weight);
333 return;
334 }
335
336 if (llvm::sys::fs::is_directory(Status)) {
337 std::error_code EC;
338 for (llvm::sys::fs::recursive_directory_iterator F(Filename, EC), E;
339 F != E && !EC; F.increment(EC)) {
340 if (llvm::sys::fs::is_regular_file(F->path())) {
341 addWeightedInput(WNI, {F->path(), Weight});
342 }
343 }
344 if (EC)
345 exitWithErrorCode(EC, Filename);
346 }
324347 }
325348
326349 static void parseInputFilenamesFile(MemoryBuffer *Buffer,
338361 continue;
339362 // If there's no comma, it's an unweighted profile.
340363 else if (SanitizedEntry.find(',') == StringRef::npos)
341 WFV.emplace_back(SanitizedEntry, 1);
364 addWeightedInput(WFV, {SanitizedEntry, 1});
342365 else
343 WFV.emplace_back(parseWeightedFile(SanitizedEntry));
366 addWeightedInput(WFV, parseWeightedFile(SanitizedEntry));
344367 }
345368 }
346369
386409
387410 WeightedFileVector WeightedInputs;
388411 for (StringRef Filename : InputFilenames)
389 WeightedInputs.emplace_back(Filename, 1);
412 addWeightedInput(WeightedInputs, {Filename, 1});
390413 for (StringRef WeightedFilename : WeightedInputFilenames)
391 WeightedInputs.emplace_back(parseWeightedFile(WeightedFilename));
414 addWeightedInput(WeightedInputs, parseWeightedFile(WeightedFilename));
392415
393416 // Make sure that the file buffer stays alive for the duration of the
394417 // weighted input vector's lifetime.