[ELF] Move parse files from Driver.cpp to InputFiles.cpp. NFC

Fixes: 36146d2b6be53e5e98dee3c1fce8699db9615728

When `doParseFile template defintion` in InputFiles.cpp is optimized
out, we will get a link failure. Actually, we can move the file parsing
loop from Driver.too to InputFiles.cpp and merge it with
parseArmCMSEImportLib.

GitOrigin-RevId: f1f06f31b89683e76b87c7665c3318df37ebb6c7
diff --git a/ELF/Driver.cpp b/ELF/Driver.cpp
index 7257ebd..65d0fa9 100644
--- a/ELF/Driver.cpp
+++ b/ELF/Driver.cpp
@@ -2725,19 +2725,7 @@
   for (StringRef name : config->undefined)
     addUnusedUndefined(name)->referenced = true;
 
-  // Add all files to the symbol table. This will add almost all
-  // symbols that we need to the symbol table. This process might
-  // add files to the link, via autolinking, these files are always
-  // appended to the Files vector.
-  {
-    llvm::TimeTraceScope timeScope("Parse input files");
-    for (size_t i = 0; i < files.size(); ++i) {
-      llvm::TimeTraceScope timeScope("Parse input files", files[i]->getName());
-      doParseFile<ELFT>(files[i]);
-    }
-    if (armCmseImpLib)
-      parseArmCMSEImportLib(*armCmseImpLib);
-  }
+  parseFiles(files, armCmseImpLib);
 
   // Now that we have every file, we can decide if we will need a
   // dynamic symbol table.
diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp
index 1104433..42761b6 100644
--- a/ELF/InputFiles.cpp
+++ b/ELF/InputFiles.cpp
@@ -288,7 +288,7 @@
   return false;
 }
 
-template <class ELFT> void elf::doParseFile(InputFile *file) {
+template <class ELFT> static void doParseFile(InputFile *file) {
   if (!isCompatible(file))
     return;
 
@@ -330,12 +330,24 @@
 extern template void ObjFile<ELF64LE>::importCmseSymbols();
 extern template void ObjFile<ELF64BE>::importCmseSymbols();
 
-template <class ELFT> static void doParseArmCMSEImportLib(InputFile &file) {
-  cast<ObjFile<ELFT>>(file).importCmseSymbols();
+template <class ELFT>
+static void doParseFiles(const std::vector<InputFile *> &files,
+                         InputFile *armCmseImpLib) {
+  // Add all files to the symbol table. This will add almost all symbols that we
+  // need to the symbol table. This process might add files to the link due to
+  // addDependentLibrary.
+  for (size_t i = 0; i < files.size(); ++i) {
+    llvm::TimeTraceScope timeScope("Parse input files", files[i]->getName());
+    doParseFile<ELFT>(files[i]);
+  }
+  if (armCmseImpLib)
+    cast<ObjFile<ELFT>>(*armCmseImpLib).importCmseSymbols();
 }
 
-void elf::parseArmCMSEImportLib(InputFile &file) {
-  invokeELFT(doParseArmCMSEImportLib, file);
+void elf::parseFiles(const std::vector<InputFile *> &files,
+                     InputFile *armCmseImpLib) {
+  llvm::TimeTraceScope timeScope("Parse input files");
+  invokeELFT(doParseFiles, files, armCmseImpLib);
 }
 
 // Concatenates arguments to construct a string representing an error location.
diff --git a/ELF/InputFiles.h b/ELF/InputFiles.h
index 7d5dd34..9519759 100644
--- a/ELF/InputFiles.h
+++ b/ELF/InputFiles.h
@@ -46,10 +46,9 @@
 std::optional<MemoryBufferRef> readFile(StringRef path);
 
 // Add symbols in File to the symbol table.
-template <class ELFT> void doParseFile(InputFile *file);
 void parseFile(InputFile *file);
-
-void parseArmCMSEImportLib(InputFile &file);
+void parseFiles(const std::vector<InputFile *> &files,
+                InputFile *armCmseImpLib);
 
 // The root class of input files.
 class InputFile {