aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-cgdata/llvm-cgdata.cpp
diff options
context:
space:
mode:
authorKyungwoo Lee <kyulee@meta.com>2024-09-09 19:38:05 -0700
committerKyungwoo Lee <kyulee@meta.com>2024-10-27 00:13:00 -0700
commitc7913f9fff736da4cc6a78a17e41dc539bc75e8a (patch)
treeb23e15800d3e8119b4385dfe95896fccba57623e /llvm/tools/llvm-cgdata/llvm-cgdata.cpp
parent8e10ed3b27b0f0098782171bb38387e86536be5f (diff)
downloadllvm-upstream/users/kyulee-com/cgdata.tar.gz
llvm-upstream/users/kyulee-com/cgdata.tar.bz2
llvm-upstream/users/kyulee-com/cgdata.zip
[CGData][llvm-cgdata] Support for stable function mapupstream/users/kyulee-com/cgdata
This introduces a new cgdata format for stable function maps. The raw data is embedded in the __llvm_merge section during compile time. This data can be read and merged using the llvm-cgdata tool, into an indexed cgdata file. Consequently, the tool is now capable of handling either outlined hash trees, stable function maps, or both, as they are orthogonal.
Diffstat (limited to 'llvm/tools/llvm-cgdata/llvm-cgdata.cpp')
-rw-r--r--llvm/tools/llvm-cgdata/llvm-cgdata.cpp48
1 files changed, 36 insertions, 12 deletions
diff --git a/llvm/tools/llvm-cgdata/llvm-cgdata.cpp b/llvm/tools/llvm-cgdata/llvm-cgdata.cpp
index 483f46626312..0931cad4bcb7 100644
--- a/llvm/tools/llvm-cgdata/llvm-cgdata.cpp
+++ b/llvm/tools/llvm-cgdata/llvm-cgdata.cpp
@@ -80,8 +80,6 @@ static CGDataAction Action;
static std::optional<CGDataFormat> OutputFormat;
static std::vector<std::string> InputFilenames;
-// TODO: Add a doc, https://llvm.org/docs/CommandGuide/llvm-cgdata.html
-
static void exitWithError(Twine Message, std::string Whence = "",
std::string Hint = "") {
WithColor::error();
@@ -128,6 +126,10 @@ static int convert_main(int argc, const char *argv[]) {
OutlinedHashTreeRecord Record(Reader->releaseOutlinedHashTree());
Writer.addRecord(Record);
}
+ if (Reader->hasStableFunctionMap()) {
+ StableFunctionMapRecord Record(Reader->releaseStableFunctionMap());
+ Writer.addRecord(Record);
+ }
if (OutputFormat == CGDataFormat::Text) {
if (Error E = Writer.writeText(OS))
@@ -141,10 +143,12 @@ static int convert_main(int argc, const char *argv[]) {
}
static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
- OutlinedHashTreeRecord &GlobalOutlineRecord);
+ OutlinedHashTreeRecord &GlobalOutlineRecord,
+ StableFunctionMapRecord &GlobalFunctionMapRecord);
static bool handleArchive(StringRef Filename, Archive &Arch,
- OutlinedHashTreeRecord &GlobalOutlineRecord) {
+ OutlinedHashTreeRecord &GlobalOutlineRecord,
+ StableFunctionMapRecord &GlobalFunctionMapRecord) {
bool Result = true;
Error Err = Error::success();
for (const auto &Child : Arch.children(Err)) {
@@ -155,7 +159,8 @@ static bool handleArchive(StringRef Filename, Archive &Arch,
if (Error E = NameOrErr.takeError())
exitWithError(std::move(E), Filename);
std::string Name = (Filename + "(" + NameOrErr.get() + ")").str();
- Result &= handleBuffer(Name, BuffOrErr.get(), GlobalOutlineRecord);
+ Result &= handleBuffer(Name, BuffOrErr.get(), GlobalOutlineRecord,
+ GlobalFunctionMapRecord);
}
if (Err)
exitWithError(std::move(Err), Filename);
@@ -163,7 +168,8 @@ static bool handleArchive(StringRef Filename, Archive &Arch,
}
static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
- OutlinedHashTreeRecord &GlobalOutlineRecord) {
+ OutlinedHashTreeRecord &GlobalOutlineRecord,
+ StableFunctionMapRecord &GlobalFunctionMapRecord) {
Expected<std::unique_ptr<object::Binary>> BinOrErr =
object::createBinary(Buffer);
if (Error E = BinOrErr.takeError())
@@ -171,11 +177,12 @@ static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
bool Result = true;
if (auto *Obj = dyn_cast<ObjectFile>(BinOrErr->get())) {
- if (Error E =
- CodeGenDataReader::mergeFromObjectFile(Obj, GlobalOutlineRecord))
+ if (Error E = CodeGenDataReader::mergeFromObjectFile(
+ Obj, GlobalOutlineRecord, GlobalFunctionMapRecord))
exitWithError(std::move(E), Filename);
} else if (auto *Arch = dyn_cast<Archive>(BinOrErr->get())) {
- Result &= handleArchive(Filename, *Arch, GlobalOutlineRecord);
+ Result &= handleArchive(Filename, *Arch, GlobalOutlineRecord,
+ GlobalFunctionMapRecord);
} else {
// TODO: Support for the MachO universal binary format.
errs() << "Error: unsupported binary file: " << Filename << "\n";
@@ -186,26 +193,34 @@ static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
}
static bool handleFile(StringRef Filename,
- OutlinedHashTreeRecord &GlobalOutlineRecord) {
+ OutlinedHashTreeRecord &GlobalOutlineRecord,
+ StableFunctionMapRecord &GlobalFunctionMapRecord) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BuffOrErr =
MemoryBuffer::getFileOrSTDIN(Filename);
if (std::error_code EC = BuffOrErr.getError())
exitWithErrorCode(EC, Filename);
- return handleBuffer(Filename, *BuffOrErr.get(), GlobalOutlineRecord);
+ return handleBuffer(Filename, *BuffOrErr.get(), GlobalOutlineRecord,
+ GlobalFunctionMapRecord);
}
static int merge_main(int argc, const char *argv[]) {
bool Result = true;
OutlinedHashTreeRecord GlobalOutlineRecord;
+ StableFunctionMapRecord GlobalFunctionMapRecord;
for (auto &Filename : InputFilenames)
- Result &= handleFile(Filename, GlobalOutlineRecord);
+ Result &=
+ handleFile(Filename, GlobalOutlineRecord, GlobalFunctionMapRecord);
if (!Result)
exitWithError("failed to merge codegen data files.");
+ GlobalFunctionMapRecord.finalize();
+
CodeGenDataWriter Writer;
if (!GlobalOutlineRecord.empty())
Writer.addRecord(GlobalOutlineRecord);
+ if (!GlobalFunctionMapRecord.empty())
+ Writer.addRecord(GlobalFunctionMapRecord);
std::error_code EC;
raw_fd_ostream OS(OutputFilename, EC,
@@ -249,6 +264,15 @@ static int show_main(int argc, const char *argv[]) {
<< "\n";
OS << " Depth: " << Tree->depth() << "\n";
}
+ if (Reader->hasStableFunctionMap()) {
+ auto Map = Reader->releaseStableFunctionMap();
+ OS << "Stable function map:\n";
+ OS << " Unique hash Count: " << Map->size() << "\n";
+ OS << " Total function Count: "
+ << Map->size(StableFunctionMap::TotalFunctionCount) << "\n";
+ OS << " Mergeable function Count: "
+ << Map->size(StableFunctionMap::MergeableFunctionCount) << "\n";
+ }
return 0;
}