[PATCH] D119892: [lld-macho][nfc] Factor out callgraph parsing code
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 15 18:16:17 PST 2022
This revision was automatically updated to reflect the committed changes.
int3 marked an inline comment as done.
Closed by commit rG94c28d289aec: [lld-macho][nfc] Factor out callgraph parsing code (authored by int3).
Changed prior to commit:
https://reviews.llvm.org/D119892?vs=409053&id=409116#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119892/new/
https://reviews.llvm.org/D119892
Files:
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
lld/MachO/InputSection.h
Index: lld/MachO/InputSection.h
===================================================================
--- lld/MachO/InputSection.h
+++ lld/MachO/InputSection.h
@@ -283,6 +283,7 @@
constexpr const char bitcodeBundle[] = "__bundle";
constexpr const char cString[] = "__cstring";
constexpr const char cfString[] = "__cfstring";
+constexpr const char cgProfile[] = "__cg_profile";
constexpr const char codeSignature[] = "__code_signature";
constexpr const char common[] = "__common";
constexpr const char compactUnwind[] = "__compact_unwind";
Index: lld/MachO/InputFiles.h
===================================================================
--- lld/MachO/InputFiles.h
+++ lld/MachO/InputFiles.h
@@ -86,6 +86,9 @@
uint32_t toIndex;
// Number of calls from callee to caller in the profile.
uint64_t count;
+
+ CallGraphEntry(uint32_t fromIndex, uint32_t toIndex, uint64_t count)
+ : fromIndex(fromIndex), toIndex(toIndex), count(count) {}
};
class InputFile {
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -262,6 +262,24 @@
return {};
}
+static Error parseCallGraph(ArrayRef<uint8_t> data,
+ std::vector<CallGraphEntry> &callGraph) {
+ TimeTraceScope timeScope("Parsing call graph section");
+ BinaryStreamReader reader(data, support::little);
+ while (!reader.empty()) {
+ uint32_t fromIndex, toIndex;
+ uint64_t count;
+ if (Error err = reader.readInteger(fromIndex))
+ return err;
+ if (Error err = reader.readInteger(toIndex))
+ return err;
+ if (Error err = reader.readInteger(count))
+ return err;
+ callGraph.emplace_back(fromIndex, toIndex, count);
+ }
+ return Error::success();
+}
+
// Parse the sequence of sections within a single LC_SEGMENT(_64).
// Split each section into subsections.
template <class SectionHeader>
@@ -320,25 +338,8 @@
if (name == section_names::compactUnwind)
compactUnwindSection = sections.back();
} else if (segname == segment_names::llvm) {
- if (name == "__cg_profile" && config->callGraphProfileSort) {
- TimeTraceScope timeScope("Parsing call graph section");
- BinaryStreamReader reader(data, support::little);
- while (!reader.empty()) {
- uint32_t fromIndex, toIndex;
- uint64_t count;
- if (Error err = reader.readInteger(fromIndex))
- fatal(toString(this) + ": Expected 32-bit integer");
- if (Error err = reader.readInteger(toIndex))
- fatal(toString(this) + ": Expected 32-bit integer");
- if (Error err = reader.readInteger(count))
- fatal(toString(this) + ": Expected 64-bit integer");
- callGraph.emplace_back();
- CallGraphEntry &entry = callGraph.back();
- entry.fromIndex = fromIndex;
- entry.toIndex = toIndex;
- entry.count = count;
- }
- }
+ if (config->callGraphProfileSort && name == section_names::cgProfile)
+ checkError(parseCallGraph(data, callGraph));
// ld64 does not appear to emit contents from sections within the __LLVM
// segment. Symbols within those sections point to bitcode metadata
// instead of actual symbols. Global symbols within those sections could
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119892.409116.patch
Type: text/x-patch
Size: 3351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220216/8a5d5136/attachment.bin>
More information about the llvm-commits
mailing list