Revert r276185 -- build bot failure 

llvm-svn: 276194
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index b2da3c2..26ce4cc 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -109,12 +109,12 @@
 }
 
 struct WeightedFile {
-  std::string Filename;
+  StringRef Filename;
   uint64_t Weight;
 
   WeightedFile() {}
 
-  WeightedFile(const std::string &F, uint64_t W) : Filename{F}, Weight{W} {}
+  WeightedFile(StringRef F, uint64_t W) : Filename{F}, Weight{W} {}
 };
 typedef SmallVector<WeightedFile, 5> WeightedFileVector;
 
@@ -305,6 +305,10 @@
   if (WeightStr.getAsInteger(10, Weight) || Weight < 1)
     exitWithError("Input weight must be a positive integer.");
 
+  if (!sys::fs::exists(FileName))
+    exitWithErrorCode(make_error_code(errc::no_such_file_or_directory),
+                      FileName);
+
   return WeightedFile(FileName, Weight);
 }
 
@@ -320,33 +324,6 @@
   return std::move(*BufOrError);
 }
 
-static void addWeightedInput(WeightedFileVector &WNI, const WeightedFile &WF) {
-  StringRef Filename = WF.Filename;
-  uint64_t Weight = WF.Weight;
-  llvm::sys::fs::file_status Status;
-  llvm::sys::fs::status(Filename, Status);
-  if (!llvm::sys::fs::exists(Status))
-    exitWithErrorCode(make_error_code(errc::no_such_file_or_directory),
-                      Filename);
-  // If it's a source file, collect it.
-  if (llvm::sys::fs::is_regular_file(Status)) {
-    WNI.emplace_back(Filename, Weight);
-    return;
-  }
-
-  if (llvm::sys::fs::is_directory(Status)) {
-    std::error_code EC;
-    for (llvm::sys::fs::recursive_directory_iterator F(Filename, EC), E;
-         F != E && !EC; F.increment(EC)) {
-      if (llvm::sys::fs::is_regular_file(F->path())) {
-        addWeightedInput(WNI, {F->path(), Weight});
-      }
-    }
-    if (EC)
-      exitWithErrorCode(EC, Filename);
-  }
-}
-
 static void parseInputFilenamesFile(MemoryBuffer *Buffer,
                                     WeightedFileVector &WFV) {
   if (!Buffer)
@@ -362,9 +339,9 @@
       continue;
     // If there's no comma, it's an unweighted profile.
     else if (SanitizedEntry.find(',') == StringRef::npos)
-      addWeightedInput(WFV, {SanitizedEntry, 1});
+      WFV.emplace_back(SanitizedEntry, 1);
     else
-      addWeightedInput(WFV, parseWeightedFile(SanitizedEntry));
+      WFV.emplace_back(parseWeightedFile(SanitizedEntry));
   }
 }
 
@@ -410,9 +387,9 @@
 
   WeightedFileVector WeightedInputs;
   for (StringRef Filename : InputFilenames)
-    addWeightedInput(WeightedInputs, {Filename, 1});
+    WeightedInputs.emplace_back(Filename, 1);
   for (StringRef WeightedFilename : WeightedInputFilenames)
-    addWeightedInput(WeightedInputs, parseWeightedFile(WeightedFilename));
+    WeightedInputs.emplace_back(parseWeightedFile(WeightedFilename));
 
   // Make sure that the file buffer stays alive for the duration of the
   // weighted input vector's lifetime.