[PATCH] D49136: [ELF] - Refactor readCallGraph(). NFCI.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 10 07:44:14 PDT 2018
grimar created this revision.
grimar added a reviewer: ruiu.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
I suggest doing this change to eliminate code duplication.
It's NFC except that it removes early exit for `Count == 0`
which does not seem to be useful (we have no such tests either).
https://reviews.llvm.org/D49136
Files:
ELF/Driver.cpp
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -628,33 +628,28 @@
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;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49136.154806.patch
Type: text/x-patch
Size: 2098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180710/089aab38/attachment.bin>
More information about the llvm-commits
mailing list