diff options
| author | Kyungwoo Lee <kyulee@meta.com> | 2024-09-09 19:38:05 -0700 |
|---|---|---|
| committer | Kyungwoo Lee <kyulee@meta.com> | 2024-10-27 00:13:00 -0700 |
| commit | c7913f9fff736da4cc6a78a17e41dc539bc75e8a (patch) | |
| tree | b23e15800d3e8119b4385dfe95896fccba57623e /llvm/lib/CGData/CodeGenDataWriter.cpp | |
| parent | 8e10ed3b27b0f0098782171bb38387e86536be5f (diff) | |
| download | llvm-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/lib/CGData/CodeGenDataWriter.cpp')
| -rw-r--r-- | llvm/lib/CGData/CodeGenDataWriter.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/llvm/lib/CGData/CodeGenDataWriter.cpp b/llvm/lib/CGData/CodeGenDataWriter.cpp index 5f638be0fefe..3a392036198a 100644 --- a/llvm/lib/CGData/CodeGenDataWriter.cpp +++ b/llvm/lib/CGData/CodeGenDataWriter.cpp @@ -52,6 +52,13 @@ void CodeGenDataWriter::addRecord(OutlinedHashTreeRecord &Record) { DataKind |= CGDataKind::FunctionOutlinedHashTree; } +void CodeGenDataWriter::addRecord(StableFunctionMapRecord &Record) { + assert(Record.FunctionMap && "empty function map in the record"); + FunctionMapRecord.FunctionMap = std::move(Record.FunctionMap); + + DataKind |= CGDataKind::StableFunctionMergingMap; +} + Error CodeGenDataWriter::write(raw_fd_ostream &OS) { CGDataOStream COS(OS); return writeImpl(COS); @@ -68,8 +75,11 @@ Error CodeGenDataWriter::writeHeader(CGDataOStream &COS) { if (static_cast<bool>(DataKind & CGDataKind::FunctionOutlinedHashTree)) Header.DataKind |= static_cast<uint32_t>(CGDataKind::FunctionOutlinedHashTree); - + if (static_cast<bool>(DataKind & CGDataKind::StableFunctionMergingMap)) + Header.DataKind |= + static_cast<uint32_t>(CGDataKind::StableFunctionMergingMap); Header.OutlinedHashTreeOffset = 0; + Header.StableFunctionMapOffset = 0; // Only write up to the CGDataKind. We need to remember the offset of the // remaining fields to allow back-patching later. @@ -83,6 +93,12 @@ Error CodeGenDataWriter::writeHeader(CGDataOStream &COS) { // Reserve the space for OutlinedHashTreeOffset field. COS.write(0); + // Save the location of Header.StableFunctionMapOffset field in \c COS. + StableFunctionMapOffset = COS.tell(); + + // Reserve the space for StableFunctionMapOffset field. + COS.write(0); + return Error::success(); } @@ -93,10 +109,14 @@ Error CodeGenDataWriter::writeImpl(CGDataOStream &COS) { uint64_t OutlinedHashTreeFieldStart = COS.tell(); if (hasOutlinedHashTree()) HashTreeRecord.serialize(COS.OS); + uint64_t StableFunctionMapFieldStart = COS.tell(); + if (hasStableFunctionMap()) + FunctionMapRecord.serialize(COS.OS); // Back patch the offsets. CGDataPatchItem PatchItems[] = { - {OutlinedHashTreeOffset, &OutlinedHashTreeFieldStart, 1}}; + {OutlinedHashTreeOffset, &OutlinedHashTreeFieldStart, 1}, + {StableFunctionMapOffset, &StableFunctionMapFieldStart, 1}}; COS.patch(PatchItems); return Error::success(); @@ -106,6 +126,9 @@ Error CodeGenDataWriter::writeHeaderText(raw_fd_ostream &OS) { if (hasOutlinedHashTree()) OS << "# Outlined stable hash tree\n:outlined_hash_tree\n"; + if (hasStableFunctionMap()) + OS << "# Stable function map\n:stable_function_map\n"; + // TODO: Add more data types in this header return Error::success(); @@ -119,6 +142,9 @@ Error CodeGenDataWriter::writeText(raw_fd_ostream &OS) { if (hasOutlinedHashTree()) HashTreeRecord.serializeYAML(YOS); + if (hasStableFunctionMap()) + FunctionMapRecord.serializeYAML(YOS); + // TODO: Write more yaml cgdata in order return Error::success(); |
