speed up Archive::isBytecodeArchive in the case when the archive doesn't have
authorChris Lattner <sabre@nondot.org>
Fri, 23 Sep 2005 06:22:58 +0000 (06:22 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 23 Sep 2005 06:22:58 +0000 (06:22 +0000)
an llvm-ranlib symtab.  This speeds up gccld -native on an almost empty .o file
from 1.63s to 0.18s.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23406 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Archive/ArchiveReader.cpp
lib/Bytecode/Archive/ArchiveReader.cpp

index 8d87a6777e807143e6318caa7c3d32385850ab9a..ff8c9bcb0321c3a7a8e551c89e6407d239462f21 100644 (file)
@@ -504,19 +504,15 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
   }
 }
 
-bool
-Archive::isBytecodeArchive()
-{
-  //Make sure the symTab has been loaded...
-  //in most cases this should have been done
-  //when the archive was constructed, but still,
-  //this is just in case.
-  if ( !symTab.size() )
+bool Archive::isBytecodeArchive() {
+  // Make sure the symTab has been loaded. In most cases this should have been
+  // done when the archive was constructed, but still,  this is just in case.
+  if (!symTab.size())
     loadSymbolTable();
 
-  //Now that we know it's been loaded, return true
-  //if it has a size
-  if ( symTab.size() ) return true;
+  // Now that we know it's been loaded, return true
+  // if it has a size
+  if (symTab.size()) return true;
 
   //We still can't be sure it isn't a bytecode archive
   loadArchive();
@@ -524,11 +520,21 @@ Archive::isBytecodeArchive()
   std::vector<Module *> Modules;
   std::string ErrorMessage;
 
-  //If getAllModules gives an error then this isn't a proper
-  //bytecode archive
-  if ( getAllModules( Modules, &ErrorMessage ) ) return false;
-
-  //Finally, if we find any bytecode modules then this is a proper
-  //bytecode archive
-  return Modules.size();
+  // Scan the archive, trying to load a bytecode member.  We only load one to
+  // see if this works.
+  for (iterator I = begin(), E = end(); I != E; ++I) {
+    if (!I->isBytecode() && !I->isCompressedBytecode())
+      continue;
+    
+    std::string FullMemberName = 
+      archPath.toString() + "(" + I->getPath().toString() + ")";
+    Module* M = ParseBytecodeBuffer((const unsigned char*)I->getData(),
+                                    I->getSize(), FullMemberName);
+    if (!M)
+      return false;  // Couldn't parse bytecode, not a bytecode archive.
+    delete M;
+    return true;
+  }
+  
+  return false;
 }
index 8d87a6777e807143e6318caa7c3d32385850ab9a..ff8c9bcb0321c3a7a8e551c89e6407d239462f21 100644 (file)
@@ -504,19 +504,15 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
   }
 }
 
-bool
-Archive::isBytecodeArchive()
-{
-  //Make sure the symTab has been loaded...
-  //in most cases this should have been done
-  //when the archive was constructed, but still,
-  //this is just in case.
-  if ( !symTab.size() )
+bool Archive::isBytecodeArchive() {
+  // Make sure the symTab has been loaded. In most cases this should have been
+  // done when the archive was constructed, but still,  this is just in case.
+  if (!symTab.size())
     loadSymbolTable();
 
-  //Now that we know it's been loaded, return true
-  //if it has a size
-  if ( symTab.size() ) return true;
+  // Now that we know it's been loaded, return true
+  // if it has a size
+  if (symTab.size()) return true;
 
   //We still can't be sure it isn't a bytecode archive
   loadArchive();
@@ -524,11 +520,21 @@ Archive::isBytecodeArchive()
   std::vector<Module *> Modules;
   std::string ErrorMessage;
 
-  //If getAllModules gives an error then this isn't a proper
-  //bytecode archive
-  if ( getAllModules( Modules, &ErrorMessage ) ) return false;
-
-  //Finally, if we find any bytecode modules then this is a proper
-  //bytecode archive
-  return Modules.size();
+  // Scan the archive, trying to load a bytecode member.  We only load one to
+  // see if this works.
+  for (iterator I = begin(), E = end(); I != E; ++I) {
+    if (!I->isBytecode() && !I->isCompressedBytecode())
+      continue;
+    
+    std::string FullMemberName = 
+      archPath.toString() + "(" + I->getPath().toString() + ")";
+    Module* M = ParseBytecodeBuffer((const unsigned char*)I->getData(),
+                                    I->getSize(), FullMemberName);
+    if (!M)
+      return false;  // Couldn't parse bytecode, not a bytecode archive.
+    delete M;
+    return true;
+  }
+  
+  return false;
 }