[llvm] [ThinLTO][BitcodeWriter] Write import type in per-module combined summary (PR #87600)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Mon May 6 18:57:16 PDT 2024
https://github.com/minglotus-6 updated https://github.com/llvm/llvm-project/pull/87600
>From 78fa2e09ac19594baced9dfd27b4ae196f087056 Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Wed, 3 Apr 2024 21:45:50 -0700
Subject: [PATCH 1/3] [ThinLTO]Record import type (declaration or definition)
in GlobalValueSummary::GVFlags
- This change doesn't set the bit in the summaries, just make the code changes.
---
llvm/include/llvm/AsmParser/LLToken.h | 1 +
llvm/include/llvm/IR/ModuleSummaryIndex.h | 14 +++++++++++---
llvm/include/llvm/IR/ModuleSummaryIndexYAML.h | 7 ++++---
llvm/lib/Analysis/ModuleSummaryAnalysis.cpp | 12 ++++++++----
llvm/lib/AsmParser/LLParser.cpp | 15 ++++++++++++---
llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 3 ++-
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 5 ++++-
7 files changed, 42 insertions(+), 15 deletions(-)
diff --git a/llvm/include/llvm/AsmParser/LLToken.h b/llvm/include/llvm/AsmParser/LLToken.h
index 65ccb1b81b3a87..21229683f2496b 100644
--- a/llvm/include/llvm/AsmParser/LLToken.h
+++ b/llvm/include/llvm/AsmParser/LLToken.h
@@ -370,6 +370,7 @@ enum Kind {
kw_live,
kw_dsoLocal,
kw_canAutoHide,
+ kw_importAsDec,
kw_function,
kw_insts,
kw_funcFlags,
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index d5ff15063671d8..7eba77540fa7ea 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -472,14 +472,20 @@ class GlobalValueSummary {
/// means the symbol was externally visible.
unsigned CanAutoHide : 1;
+ /// This field is written by the ThinLTO indexing step to postlink
+ /// per-module summary. It indicates whether a global value (function or
+ /// function alias, etc) should be imported as a definition or declaration.
+ unsigned ImportAsDec : 1;
+
/// Convenience Constructors
explicit GVFlags(GlobalValue::LinkageTypes Linkage,
GlobalValue::VisibilityTypes Visibility,
bool NotEligibleToImport, bool Live, bool IsLocal,
- bool CanAutoHide)
+ bool CanAutoHide, bool ImportAsDec)
: Linkage(Linkage), Visibility(Visibility),
NotEligibleToImport(NotEligibleToImport), Live(Live),
- DSOLocal(IsLocal), CanAutoHide(CanAutoHide) {}
+ DSOLocal(IsLocal), CanAutoHide(CanAutoHide),
+ ImportAsDec(ImportAsDec) {}
};
private:
@@ -564,6 +570,8 @@ class GlobalValueSummary {
bool canAutoHide() const { return Flags.CanAutoHide; }
+ bool shouldImportAsDec() const { return Flags.ImportAsDec; }
+
GlobalValue::VisibilityTypes getVisibility() const {
return (GlobalValue::VisibilityTypes)Flags.Visibility;
}
@@ -813,7 +821,7 @@ class FunctionSummary : public GlobalValueSummary {
GlobalValue::LinkageTypes::AvailableExternallyLinkage,
GlobalValue::DefaultVisibility,
/*NotEligibleToImport=*/true, /*Live=*/true, /*IsLocal=*/false,
- /*CanAutoHide=*/false),
+ /*CanAutoHide=*/false, /*ImportAsDec=*/false),
/*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0,
std::vector<ValueInfo>(), std::move(Edges),
std::vector<GlobalValue::GUID>(),
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
index 33e57e5f2102fd..21dddcf0c03dcd 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
@@ -137,7 +137,7 @@ template <> struct MappingTraits<TypeIdSummary> {
struct FunctionSummaryYaml {
unsigned Linkage, Visibility;
- bool NotEligibleToImport, Live, IsLocal, CanAutoHide;
+ bool NotEligibleToImport, Live, IsLocal, CanAutoHide, ImportAsDec;
std::vector<uint64_t> Refs;
std::vector<uint64_t> TypeTests;
std::vector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
@@ -227,7 +227,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
static_cast<GlobalValue::LinkageTypes>(FSum.Linkage),
static_cast<GlobalValue::VisibilityTypes>(FSum.Visibility),
FSum.NotEligibleToImport, FSum.Live, FSum.IsLocal,
- FSum.CanAutoHide),
+ FSum.CanAutoHide, FSum.ImportAsDec),
/*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0, Refs,
ArrayRef<FunctionSummary::EdgeTy>{}, std::move(FSum.TypeTests),
std::move(FSum.TypeTestAssumeVCalls),
@@ -251,7 +251,8 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
static_cast<bool>(FSum->flags().NotEligibleToImport),
static_cast<bool>(FSum->flags().Live),
static_cast<bool>(FSum->flags().DSOLocal),
- static_cast<bool>(FSum->flags().CanAutoHide), Refs,
+ static_cast<bool>(FSum->flags().CanAutoHide),
+ static_cast<bool>(FSum->flags().ImportAsDec), Refs,
FSum->type_tests(), FSum->type_test_assume_vcalls(),
FSum->type_checked_load_vcalls(),
FSum->type_test_assume_const_vcalls(),
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 3ad0bab827a512..eb81de81e476dd 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -635,7 +635,8 @@ static void computeFunctionSummary(
HasIndirBranchToBlockAddress || HasIFuncCall;
GlobalValueSummary::GVFlags Flags(
F.getLinkage(), F.getVisibility(), NotEligibleForImport,
- /* Live = */ false, F.isDSOLocal(), F.canBeOmittedFromSymbolTable());
+ /* Live = */ false, F.isDSOLocal(), F.canBeOmittedFromSymbolTable(),
+ /*ImportAsDec=*/false);
FunctionSummary::FFlags FunFlags{
F.doesNotAccessMemory(), F.onlyReadsMemory() && !F.doesNotAccessMemory(),
F.hasFnAttribute(Attribute::NoRecurse), F.returnDoesNotAlias(),
@@ -761,7 +762,8 @@ static void computeVariableSummary(ModuleSummaryIndex &Index,
bool NonRenamableLocal = isNonRenamableLocal(V);
GlobalValueSummary::GVFlags Flags(
V.getLinkage(), V.getVisibility(), NonRenamableLocal,
- /* Live = */ false, V.isDSOLocal(), V.canBeOmittedFromSymbolTable());
+ /* Live = */ false, V.isDSOLocal(), V.canBeOmittedFromSymbolTable(),
+ /* ImportAsDec= */ false);
VTableFuncList VTableFuncs;
// If splitting is not enabled, then we compute the summary information
@@ -807,7 +809,8 @@ static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
bool NonRenamableLocal = isNonRenamableLocal(A);
GlobalValueSummary::GVFlags Flags(
A.getLinkage(), A.getVisibility(), NonRenamableLocal,
- /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
+ /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable(),
+ /* ImportAsDec= */ false);
auto AS = std::make_unique<AliasSummary>(Flags);
auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
assert(AliaseeVI && "Alias expects aliasee summary to be available");
@@ -887,7 +890,8 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
GlobalValue::InternalLinkage, GlobalValue::DefaultVisibility,
/* NotEligibleToImport = */ true,
/* Live = */ true,
- /* Local */ GV->isDSOLocal(), GV->canBeOmittedFromSymbolTable());
+ /* Local */ GV->isDSOLocal(), GV->canBeOmittedFromSymbolTable(),
+ /* ImportAsDec= */ false);
CantBePromoted.insert(GV->getGUID());
// Create the appropriate summary type.
if (Function *F = dyn_cast<Function>(GV)) {
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index fe49e52ae4283c..d437637f468cfd 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -9215,7 +9215,8 @@ bool LLParser::parseFunctionSummary(std::string Name, GlobalValue::GUID GUID,
GlobalValueSummary::GVFlags GVFlags = GlobalValueSummary::GVFlags(
GlobalValue::ExternalLinkage, GlobalValue::DefaultVisibility,
/*NotEligibleToImport=*/false,
- /*Live=*/false, /*IsLocal=*/false, /*CanAutoHide=*/false);
+ /*Live=*/false, /*IsLocal=*/false, /*CanAutoHide=*/false,
+ /*ImportAsDec=*/false);
unsigned InstCount;
std::vector<FunctionSummary::EdgeTy> Calls;
FunctionSummary::TypeIdInfo TypeIdInfo;
@@ -9302,7 +9303,8 @@ bool LLParser::parseVariableSummary(std::string Name, GlobalValue::GUID GUID,
GlobalValueSummary::GVFlags GVFlags = GlobalValueSummary::GVFlags(
GlobalValue::ExternalLinkage, GlobalValue::DefaultVisibility,
/*NotEligibleToImport=*/false,
- /*Live=*/false, /*IsLocal=*/false, /*CanAutoHide=*/false);
+ /*Live=*/false, /*IsLocal=*/false, /*CanAutoHide=*/false,
+ /*ImportAsDec*/ false);
GlobalVarSummary::GVarFlags GVarFlags(/*ReadOnly*/ false,
/* WriteOnly */ false,
/* Constant */ false,
@@ -9360,7 +9362,8 @@ bool LLParser::parseAliasSummary(std::string Name, GlobalValue::GUID GUID,
GlobalValueSummary::GVFlags GVFlags = GlobalValueSummary::GVFlags(
GlobalValue::ExternalLinkage, GlobalValue::DefaultVisibility,
/*NotEligibleToImport=*/false,
- /*Live=*/false, /*IsLocal=*/false, /*CanAutoHide=*/false);
+ /*Live=*/false, /*IsLocal=*/false, /*CanAutoHide=*/false,
+ /*ImportAsDec=*/false);
if (parseToken(lltok::colon, "expected ':' here") ||
parseToken(lltok::lparen, "expected '(' here") ||
parseModuleReference(ModulePath) ||
@@ -10146,6 +10149,12 @@ bool LLParser::parseGVFlags(GlobalValueSummary::GVFlags &GVFlags) {
return true;
GVFlags.CanAutoHide = Flag;
break;
+ case lltok::kw_importAsDec:
+ Lex.Lex();
+ if (parseToken(lltok::colon, "expected ':'") || parseFlag(Flag))
+ return true;
+ GVFlags.ImportAsDec = Flag;
+ break;
default:
return error(Lex.getLoc(), "expected gv flag type");
}
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index aa6c9c95ca2403..408e6f55cdecd2 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1133,6 +1133,7 @@ static GlobalValueSummary::GVFlags getDecodedGVSummaryFlags(uint64_t RawFlags,
// to getDecodedLinkage() will need to be taken into account here as above.
auto Linkage = GlobalValue::LinkageTypes(RawFlags & 0xF); // 4 bits
auto Visibility = GlobalValue::VisibilityTypes((RawFlags >> 8) & 3); // 2 bits
+ bool ImportAsDec = ((RawFlags >> 10) & 1);
RawFlags = RawFlags >> 4;
bool NotEligibleToImport = (RawFlags & 0x1) || Version < 3;
// The Live flag wasn't introduced until version 3. For dead stripping
@@ -1143,7 +1144,7 @@ static GlobalValueSummary::GVFlags getDecodedGVSummaryFlags(uint64_t RawFlags,
bool AutoHide = (RawFlags & 0x8);
return GlobalValueSummary::GVFlags(Linkage, Visibility, NotEligibleToImport,
- Live, Local, AutoHide);
+ Live, Local, AutoHide, ImportAsDec);
}
// Decode the flags for GlobalVariable in the summary
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index dd554e422516f6..5007d498e5a220 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1202,7 +1202,8 @@ static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags) {
// Decode the flags for GlobalValue in the summary. See getDecodedGVSummaryFlags
// in BitcodeReader.cpp.
-static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags) {
+static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags,
+ bool ImportAsDec = false) {
uint64_t RawFlags = 0;
RawFlags |= Flags.NotEligibleToImport; // bool
@@ -1217,6 +1218,8 @@ static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags) {
RawFlags |= (Flags.Visibility << 8); // 2 bits
+ RawFlags |= ((ImportAsDec) & (1 << 10)); // 1 bit
+
return RawFlags;
}
>From 4b4c33fc9b42ab6969d38ca300c4cbadb329c33f Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Wed, 3 Apr 2024 22:48:55 -0700
Subject: [PATCH 2/3] [ThinLTO]Generate import type in bitcode writer
---
llvm/include/llvm/Bitcode/BitcodeWriter.h | 15 +++++---
llvm/include/llvm/IR/ModuleSummaryIndex.h | 6 ++++
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 44 ++++++++++++++++++-----
3 files changed, 51 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/Bitcode/BitcodeWriter.h b/llvm/include/llvm/Bitcode/BitcodeWriter.h
index 248d33f4502ef0..e94b074d9788e6 100644
--- a/llvm/include/llvm/Bitcode/BitcodeWriter.h
+++ b/llvm/include/llvm/Bitcode/BitcodeWriter.h
@@ -102,7 +102,8 @@ class raw_ostream;
void writeIndex(
const ModuleSummaryIndex *Index,
- const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex);
+ const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
+ const ModuleToGVSummaryPtrSet *ModuleToDecSummaries);
};
/// Write the specified module to the specified raw output stream.
@@ -147,10 +148,14 @@ class raw_ostream;
/// where it will be written in a new bitcode block. This is used when
/// writing the combined index file for ThinLTO. When writing a subset of the
/// index for a distributed backend, provide the \p ModuleToSummariesForIndex
- /// map.
- void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out,
- const std::map<std::string, GVSummaryMapTy>
- *ModuleToSummariesForIndex = nullptr);
+ /// map. For each module, \p ModuleToDecSummaries specifies the set of
+ /// summaries for which the corresponding value should be imported as a
+ /// declaration (prototype).
+ void writeIndexToFile(
+ const ModuleSummaryIndex &Index, raw_ostream &Out,
+ const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex =
+ nullptr,
+ const ModuleToGVSummaryPtrSet *ModuleToDecSummaries = nullptr);
/// If EmbedBitcode is set, save a copy of the llvm IR as data in the
/// __LLVM,__bitcode section (.llvmbc on non-MacOS).
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 7eba77540fa7ea..286b51bda0e2c1 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1257,6 +1257,12 @@ using ModulePathStringTableTy = StringMap<ModuleHash>;
/// a particular module, and provide efficient access to their summary.
using GVSummaryMapTy = DenseMap<GlobalValue::GUID, GlobalValueSummary *>;
+/// A set of global value summary pointers.
+using GVSummaryPtrSet = SmallPtrSet<GlobalValueSummary *, 4>;
+
+/// The key is module path, and value is a set of global value summary pointers.
+using ModuleToGVSummaryPtrSet = std::map<std::string, GVSummaryPtrSet>;
+
/// Map of a type GUID to type id string and summary (multimap used
/// in case of GUID conflicts).
using TypeIdSummaryMapTy =
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 5007d498e5a220..51266f31451b10 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -428,6 +428,10 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
/// The combined index to write to bitcode.
const ModuleSummaryIndex &Index;
+ /// For each module, provides the set of global value summaries for which the
+ /// value (function, function alias, etc) should be imported as a declaration.
+ const ModuleToGVSummaryPtrSet *ModuleToDecSummaries = nullptr;
+
/// When writing a subset of the index for distributed backends, client
/// provides a map of modules to the corresponding GUIDs/summaries to write.
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
@@ -452,11 +456,17 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
/// Constructs a IndexBitcodeWriter object for the given combined index,
/// writing to the provided \p Buffer. When writing a subset of the index
/// for a distributed backend, provide a \p ModuleToSummariesForIndex map.
- IndexBitcodeWriter(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
- const ModuleSummaryIndex &Index,
- const std::map<std::string, GVSummaryMapTy>
- *ModuleToSummariesForIndex = nullptr)
+ /// If provided, \p ModuleToDecSummaries specifies the set of summaries for
+ /// which the corresponding functions or aliased functions should be imported
+ /// as a declaration (but not definition) for each module.
+ IndexBitcodeWriter(
+ BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
+ const ModuleSummaryIndex &Index,
+ const ModuleToGVSummaryPtrSet *ModuleToDecSummaries = nullptr,
+ const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex =
+ nullptr)
: BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
+ ModuleToDecSummaries(ModuleToDecSummaries),
ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
// Assign unique value ids to all summaries to be written, for use
// in writing out the call graph edges. Save the mapping from GUID
@@ -4544,6 +4554,17 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
unsigned AllocAbbrev = Stream.EmitAbbrev(std::move(Abbv));
+ auto shouldImportValueAsDec = [&](GlobalValueSummary *GVS) -> bool {
+ if (ModuleToDecSummaries == nullptr)
+ return false;
+ auto Iter = ModuleToDecSummaries->find(GVS->modulePath().str());
+ if (Iter == ModuleToDecSummaries->end())
+ return false;
+ // For the current module, the value for GVS should be imported as a
+ // declaration.
+ return Iter->second.contains(GVS);
+ };
+
// The aliases are emitted as a post-pass, and will point to the value
// id of the aliasee. Save them in a vector for post-processing.
SmallVector<AliasSummary *, 64> Aliases;
@@ -4654,7 +4675,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
NameVals.push_back(*ValueId);
assert(ModuleIdMap.count(FS->modulePath()));
NameVals.push_back(ModuleIdMap[FS->modulePath()]);
- NameVals.push_back(getEncodedGVSummaryFlags(FS->flags()));
+ NameVals.push_back(
+ getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDec(FS)));
NameVals.push_back(FS->instCount());
NameVals.push_back(getEncodedFFlags(FS->fflags()));
NameVals.push_back(FS->entryCount());
@@ -4703,7 +4725,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
NameVals.push_back(AliasValueId);
assert(ModuleIdMap.count(AS->modulePath()));
NameVals.push_back(ModuleIdMap[AS->modulePath()]);
- NameVals.push_back(getEncodedGVSummaryFlags(AS->flags()));
+ NameVals.push_back(
+ getEncodedGVSummaryFlags(AS->flags(), shouldImportValueAsDec(AS)));
auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
assert(AliaseeValueId);
NameVals.push_back(AliaseeValueId);
@@ -5037,8 +5060,10 @@ void BitcodeWriter::writeModule(const Module &M,
void BitcodeWriter::writeIndex(
const ModuleSummaryIndex *Index,
- const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
+ const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
+ const ModuleToGVSummaryPtrSet *ModuleToDecSummaries) {
IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index,
+ ModuleToDecSummaries,
ModuleToSummariesForIndex);
IndexWriter.write();
}
@@ -5091,12 +5116,13 @@ void IndexBitcodeWriter::write() {
// index for a distributed backend, provide a \p ModuleToSummariesForIndex map.
void llvm::writeIndexToFile(
const ModuleSummaryIndex &Index, raw_ostream &Out,
- const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
+ const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
+ const ModuleToGVSummaryPtrSet *ModuleToDecSummaries) {
SmallVector<char, 0> Buffer;
Buffer.reserve(256 * 1024);
BitcodeWriter Writer(Buffer);
- Writer.writeIndex(&Index, ModuleToSummariesForIndex);
+ Writer.writeIndex(&Index, ModuleToSummariesForIndex, ModuleToDecSummaries);
Writer.writeStrtab();
Out.write((char *)&Buffer.front(), Buffer.size());
>From 175febc5e740ba7da2ca76a6222b187ad1e28f60 Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Mon, 15 Apr 2024 22:55:57 -0700
Subject: [PATCH 3/3] rename Dec to Decl
---
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 7e845e9ed165c6..a060265a9bc8dd 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1213,7 +1213,7 @@ static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags) {
// Decode the flags for GlobalValue in the summary. See getDecodedGVSummaryFlags
// in BitcodeReader.cpp.
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags,
- bool ImportAsDec = false) {
+ bool ImportAsDecl = false) {
uint64_t RawFlags = 0;
RawFlags |= Flags.NotEligibleToImport; // bool
@@ -1228,7 +1228,8 @@ static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags,
RawFlags |= (Flags.Visibility << 8); // 2 bits
- RawFlags |= (Flags.ImportType << 10); // 1 bit
+ unsigned ImportType = Flags.ImportType | ImportAsDecl;
+ RawFlags |= (ImportType << 10); // 1 bit
return RawFlags;
}
@@ -4554,7 +4555,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
unsigned AllocAbbrev = Stream.EmitAbbrev(std::move(Abbv));
- auto shouldImportValueAsDec = [&](GlobalValueSummary *GVS) -> bool {
+ auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) -> bool {
if (ModuleToDecSummaries == nullptr)
return false;
auto Iter = ModuleToDecSummaries->find(GVS->modulePath().str());
@@ -4676,7 +4677,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
assert(ModuleIdMap.count(FS->modulePath()));
NameVals.push_back(ModuleIdMap[FS->modulePath()]);
NameVals.push_back(
- getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDec(FS)));
+ getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDecl(FS)));
NameVals.push_back(FS->instCount());
NameVals.push_back(getEncodedFFlags(FS->fflags()));
NameVals.push_back(FS->entryCount());
@@ -4726,7 +4727,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
assert(ModuleIdMap.count(AS->modulePath()));
NameVals.push_back(ModuleIdMap[AS->modulePath()]);
NameVals.push_back(
- getEncodedGVSummaryFlags(AS->flags(), shouldImportValueAsDec(AS)));
+ getEncodedGVSummaryFlags(AS->flags(), shouldImportValueAsDecl(AS)));
auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
assert(AliaseeValueId);
NameVals.push_back(AliaseeValueId);
More information about the llvm-commits
mailing list