[lld] r338953 - [ELF] - Refactor readCallGraph().

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 4 00:31:19 PDT 2018


Author: grimar
Date: Sat Aug  4 00:31:19 2018
New Revision: 338953

URL: http://llvm.org/viewvc/llvm-project?rev=338953&view=rev
Log:
[ELF] - Refactor readCallGraph().

This simplifies the code a bit.

It is NFC except that it removes early exit for Count == 0
which does not seem to be useful (we have no such tests either).

Differential revision: https://reviews.llvm.org/D49136

Modified:
    lld/trunk/ELF/Driver.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=338953&r1=338952&r2=338953&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Aug  4 00:31:19 2018
@@ -647,33 +647,28 @@ static void readCallGraph(MemoryBufferRe
     for (Symbol *Sym : File->getSymbols())
       SymbolNameToSymbol[Sym->getName()] = Sym;
 
+  auto FindSection = [&](StringRef SymName) -> InputSectionBase * {
+    const Symbol *Sym = SymbolNameToSymbol.lookup(SymName);
+    if (Sym)
+      warnUnorderableSymbol(Sym);
+    else if (Config->WarnSymbolOrdering)
+      warn(MB.getBufferIdentifier() + ": no such symbol: " + SymName);
+
+    if (const Defined *DR = dyn_cast_or_null<Defined>(Sym))
+      return dyn_cast_or_null<InputSectionBase>(DR->Section);
+    return nullptr;
+  };
+
   for (StringRef L : args::getLines(MB)) {
     SmallVector<StringRef, 3> Fields;
     L.split(Fields, ' ');
     uint64_t Count;
     if (Fields.size() != 3 || !to_integer(Fields[2], Count))
       fatal(MB.getBufferIdentifier() + ": parse error");
-    const Symbol *FromSym = SymbolNameToSymbol.lookup(Fields[0]);
-    const Symbol *ToSym = SymbolNameToSymbol.lookup(Fields[1]);
-    if (Config->WarnSymbolOrdering) {
-      if (!FromSym)
-        warn(MB.getBufferIdentifier() + ": no such symbol: " + Fields[0]);
-      if (!ToSym)
-        warn(MB.getBufferIdentifier() + ": no such symbol: " + Fields[1]);
-    }
-    if (!FromSym || !ToSym || Count == 0)
-      continue;
-    warnUnorderableSymbol(FromSym);
-    warnUnorderableSymbol(ToSym);
-    const Defined *FromSymD = dyn_cast<Defined>(FromSym);
-    const Defined *ToSymD = dyn_cast<Defined>(ToSym);
-    if (!FromSymD || !ToSymD)
-      continue;
-    const auto *FromSB = dyn_cast_or_null<InputSectionBase>(FromSymD->Section);
-    const auto *ToSB = dyn_cast_or_null<InputSectionBase>(ToSymD->Section);
-    if (!FromSB || !ToSB)
-      continue;
-    Config->CallGraphProfile[std::make_pair(FromSB, ToSB)] += Count;
+
+    if (const InputSectionBase *FromSB = FindSection(Fields[0]))
+      if (const InputSectionBase *ToSB = FindSection(Fields[1]))
+        Config->CallGraphProfile[std::make_pair(FromSB, ToSB)] += Count;
   }
 }
 




More information about the llvm-commits mailing list