aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode
diff options
context:
space:
mode:
authorMatthew Voss <matthew.voss@sony.com>2023-07-05 14:17:20 -0700
committerMatthew Voss <matthew.voss@sony.com>2023-07-05 14:53:14 -0700
commita1ca3af31eeec61cfb9d619f55b655b0eb0b9494 (patch)
treef7127bd5940108b5fec1690ab872425afcb244a2 /llvm/lib/Bitcode
parent156913cb776438f87bd1580de862eac7be79ca2a (diff)
downloadllvm-a1ca3af31eeec61cfb9d619f55b655b0eb0b9494.zip
llvm-a1ca3af31eeec61cfb9d619f55b655b0eb0b9494.tar.gz
llvm-a1ca3af31eeec61cfb9d619f55b655b0eb0b9494.tar.bz2
[llvm] A Unified LTO Bitcode Frontend
Here's a high level summary of the changes in this patch. For more information on rational, see the RFC. (https://discourse.llvm.org/t/rfc-a-unified-lto-bitcode-frontend/61774). - Add config parameter to LTO backend, specifying which LTO mode is desired when using unified LTO. - Add unified LTO flag to the summary index for efficiency. Unified LTO modules can be detected without parsing the module. - Make sure that the ModuleID is generated by incorporating more types of symbols. Differential Revision: https://reviews.llvm.org/D123803
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp55
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp5
2 files changed, 38 insertions, 22 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index ebc88c8..4f6c5f0 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -8033,14 +8033,17 @@ Expected<std::unique_ptr<ModuleSummaryIndex>> BitcodeModule::getSummary() {
return std::move(Index);
}
-static Expected<bool> getEnableSplitLTOUnitFlag(BitstreamCursor &Stream,
- unsigned ID) {
+static Expected<std::pair<bool, bool>>
+getEnableSplitLTOUnitAndUnifiedFlag(BitstreamCursor &Stream,
+ unsigned ID,
+ BitcodeLTOInfo &LTOInfo) {
if (Error Err = Stream.EnterSubBlock(ID))
return std::move(Err);
SmallVector<uint64_t, 64> Record;
while (true) {
BitstreamEntry Entry;
+ std::pair<bool, bool> Result = {false,false};
if (Error E = Stream.advanceSkippingSubblocks().moveInto(Entry))
return std::move(E);
@@ -8048,10 +8051,10 @@ static Expected<bool> getEnableSplitLTOUnitFlag(BitstreamCursor &Stream,
case BitstreamEntry::SubBlock: // Handled for us already.
case BitstreamEntry::Error:
return error("Malformed block");
- case BitstreamEntry::EndBlock:
- // If no flags record found, conservatively return true to mimic
- // behavior before this flag was added.
- return true;
+ case BitstreamEntry::EndBlock: {
+ // If no flags record found, set both flags to false.
+ return Result;
+ }
case BitstreamEntry::Record:
// The interesting case.
break;
@@ -8068,9 +8071,13 @@ static Expected<bool> getEnableSplitLTOUnitFlag(BitstreamCursor &Stream,
case bitc::FS_FLAGS: { // [flags]
uint64_t Flags = Record[0];
// Scan flags.
- assert(Flags <= 0x1ff && "Unexpected bits in flag");
+ assert(Flags <= 0x2ff && "Unexpected bits in flag");
+
+ bool EnableSplitLTOUnit = Flags & 0x8;
+ bool UnifiedLTO = Flags & 0x200;
+ Result = {EnableSplitLTOUnit, UnifiedLTO};
- return Flags & 0x8;
+ return Result;
}
}
}
@@ -8096,25 +8103,31 @@ Expected<BitcodeLTOInfo> BitcodeModule::getLTOInfo() {
return error("Malformed block");
case BitstreamEntry::EndBlock:
return BitcodeLTOInfo{/*IsThinLTO=*/false, /*HasSummary=*/false,
- /*EnableSplitLTOUnit=*/false};
+ /*EnableSplitLTOUnit=*/false, /*UnifiedLTO=*/false};
case BitstreamEntry::SubBlock:
if (Entry.ID == bitc::GLOBALVAL_SUMMARY_BLOCK_ID) {
- Expected<bool> EnableSplitLTOUnit =
- getEnableSplitLTOUnitFlag(Stream, Entry.ID);
- if (!EnableSplitLTOUnit)
- return EnableSplitLTOUnit.takeError();
- return BitcodeLTOInfo{/*IsThinLTO=*/true, /*HasSummary=*/true,
- *EnableSplitLTOUnit};
+ BitcodeLTOInfo LTOInfo;
+ Expected<std::pair<bool, bool>> Flags =
+ getEnableSplitLTOUnitAndUnifiedFlag(Stream, Entry.ID, LTOInfo);
+ if (!Flags)
+ return Flags.takeError();
+ std::tie(LTOInfo.EnableSplitLTOUnit, LTOInfo.UnifiedLTO) = Flags.get();
+ LTOInfo.IsThinLTO = true;
+ LTOInfo.HasSummary = true;
+ return LTOInfo;
}
if (Entry.ID == bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID) {
- Expected<bool> EnableSplitLTOUnit =
- getEnableSplitLTOUnitFlag(Stream, Entry.ID);
- if (!EnableSplitLTOUnit)
- return EnableSplitLTOUnit.takeError();
- return BitcodeLTOInfo{/*IsThinLTO=*/false, /*HasSummary=*/true,
- *EnableSplitLTOUnit};
+ BitcodeLTOInfo LTOInfo;
+ Expected<std::pair<bool, bool>> Flags =
+ getEnableSplitLTOUnitAndUnifiedFlag(Stream, Entry.ID, LTOInfo);
+ if (!Flags)
+ return Flags.takeError();
+ std::tie(LTOInfo.EnableSplitLTOUnit, LTOInfo.UnifiedLTO) = Flags.get();
+ LTOInfo.IsThinLTO = false;
+ LTOInfo.HasSummary = true;
+ return LTOInfo;
}
// Ignore other sub-blocks.
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index bedae66..f2bfb4e 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4086,6 +4086,9 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
// Bits 1-3 are set only in the combined index, skip them.
if (Index->enableSplitLTOUnit())
Flags |= 0x8;
+ if (Index->hasUnifiedLTO())
+ Flags |= 0x200;
+
Stream.EmitRecord(bitc::FS_FLAGS, ArrayRef<uint64_t>{Flags});
if (Index->begin() == Index->end()) {
@@ -4112,7 +4115,7 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
auto Abbv = std::make_shared<BitCodeAbbrev>();
Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_PROFILE));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
- Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // flags
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // flags
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // instcount
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // fflags
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // numrefs