Resolver: optimize fallback atoms.
authorRui Ueyama <ruiu@google.com>
Sat, 7 Mar 2015 04:23:46 +0000 (04:23 +0000)
committerRui Ueyama <ruiu@google.com>
Sat, 7 Mar 2015 04:23:46 +0000 (04:23 +0000)
Atoms with fallback atoms are never be added to the symbol table.
However, we added such atoms to _undefines array. We had to call
isCoalescedAway to identify and skip them. We should just stop
adding them in the first place.

This seems to make the linker ~1% faster in my test case.

llvm-svn: 231552

lld/lib/Core/Resolver.cpp

index 2f24e47ef8f40eaed56fbec02e6f2fb3909ff609..b9c26f040a1693eecf91e7afcb4d86d7ca0b7461 100644 (file)
@@ -54,8 +54,7 @@ void Resolver::forEachUndefines(File &file, bool searchForOverrides,
       StringRef undefName = _undefines[i];
       if (undefName.empty())
         continue;
-      const Atom *atom = _symbolTable.findByName(undefName);
-      if (!isa<UndefinedAtom>(atom) || _symbolTable.isCoalescedAway(atom)) {
+      if (_symbolTable.isDefined(undefName)) {
         // The symbol was resolved by some other file. Cache the result.
         _undefines[i] = "";
         continue;
@@ -119,18 +118,18 @@ bool Resolver::doUndefinedAtom(const UndefinedAtom &atom) {
 
   // tell symbol table
   bool newUndefAdded = _symbolTable.add(atom);
-  if (newUndefAdded)
-    _undefines.push_back(atom.name());
 
   // If the undefined symbol has an alternative name, try to resolve the
   // symbol with the name to give it a second chance. This feature is used
   // for COFF "weak external" symbol.
   if (newUndefAdded || !_symbolTable.isDefined(atom.name())) {
     if (const UndefinedAtom *fallbackAtom = atom.fallback()) {
-      doUndefinedAtom(*fallbackAtom);
       _symbolTable.addReplacement(&atom, fallbackAtom);
+      return doUndefinedAtom(*fallbackAtom);
     }
   }
+  if (newUndefAdded)
+    _undefines.push_back(atom.name());
   return newUndefAdded;
 }