[llvm] 51d3829 - [ThinLTO] Shrink FunctionSummary by 8 bytes (#107706)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 7 11:21:24 PDT 2024
Author: Kazu Hirata
Date: 2024-09-07T11:21:20-07:00
New Revision: 51d3829d8fc5beba269629903365af75174de7f6
URL: https://github.com/llvm/llvm-project/commit/51d3829d8fc5beba269629903365af75174de7f6
DIFF: https://github.com/llvm/llvm-project/commit/51d3829d8fc5beba269629903365af75174de7f6.diff
LOG: [ThinLTO] Shrink FunctionSummary by 8 bytes (#107706)
During the ThinLTO indexing step for one of our large applications, we
create 4 million instances of FunctionSummary.
Changing:
std::vector<EdgeTy> CallGraphEdgeList;
to:
SmallVector<EdgeTy, 0> CallGraphEdgeList;
in FunctionSummary reduces the size of each instance by 8 bytes. The
rest of the patch makes the same change to other places so that the
types stay compatible across function boundaries.
Added:
Modified:
llvm/include/llvm/AsmParser/LLParser.h
llvm/include/llvm/IR/ModuleSummaryIndex.h
llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/ModuleSummaryIndex.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h
index 2bbcda70938548..9576b935198dd4 100644
--- a/llvm/include/llvm/AsmParser/LLParser.h
+++ b/llvm/include/llvm/AsmParser/LLParser.h
@@ -394,7 +394,7 @@ namespace llvm {
bool parseGVFlags(GlobalValueSummary::GVFlags &GVFlags);
bool parseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags);
bool parseOptionalFFlags(FunctionSummary::FFlags &FFlags);
- bool parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls);
+ bool parseOptionalCalls(SmallVectorImpl<FunctionSummary::EdgeTy> &Calls);
bool parseHotness(CalleeInfo::HotnessType &Hotness);
bool parseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo);
bool parseTypeTests(std::vector<GlobalValue::GUID> &TypeTests);
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 701c67f1b0af2b..af3734cc2c54b5 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -851,7 +851,7 @@ class FunctionSummary : public GlobalValueSummary {
/// Create an empty FunctionSummary (with specified call edges).
/// Used to represent external nodes and the dummy root node.
static FunctionSummary
- makeDummyFunctionSummary(std::vector<FunctionSummary::EdgeTy> Edges) {
+ makeDummyFunctionSummary(SmallVectorImpl<FunctionSummary::EdgeTy> &&Edges) {
return FunctionSummary(
FunctionSummary::GVFlags(
GlobalValue::LinkageTypes::AvailableExternallyLinkage,
@@ -880,7 +880,9 @@ class FunctionSummary : public GlobalValueSummary {
FFlags FunFlags;
/// List of <CalleeValueInfo, CalleeInfo> call edge pairs from this function.
- std::vector<EdgeTy> CallGraphEdgeList;
+ /// We use SmallVector<ValueInfo, 0> instead of std::vector<ValueInfo> for its
+ /// smaller memory footprint.
+ SmallVector<EdgeTy, 0> CallGraphEdgeList;
std::unique_ptr<TypeIdInfo> TIdInfo;
@@ -910,7 +912,7 @@ class FunctionSummary : public GlobalValueSummary {
public:
FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags,
SmallVectorImpl<ValueInfo> &&Refs,
- std::vector<EdgeTy> CGEdges,
+ SmallVectorImpl<EdgeTy> &&CGEdges,
std::vector<GlobalValue::GUID> TypeTests,
std::vector<VFuncId> TypeTestAssumeVCalls,
std::vector<VFuncId> TypeCheckedLoadVCalls,
@@ -957,7 +959,7 @@ class FunctionSummary : public GlobalValueSummary {
/// Return the list of <CalleeValueInfo, CalleeInfo> pairs.
ArrayRef<EdgeTy> calls() const { return CallGraphEdgeList; }
- std::vector<EdgeTy> &mutableCalls() { return CallGraphEdgeList; }
+ SmallVector<EdgeTy, 0> &mutableCalls() { return CallGraphEdgeList; }
void addCall(EdgeTy E) { CallGraphEdgeList.push_back(E); }
@@ -1535,7 +1537,7 @@ class ModuleSummaryIndex {
discoverNodes(ValueInfo(HaveGVs, &S), FunctionHasParent);
}
- std::vector<FunctionSummary::EdgeTy> Edges;
+ SmallVector<FunctionSummary::EdgeTy, 0> Edges;
// create edges to all roots in the Index
for (auto &P : FunctionHasParent) {
if (P.second)
@@ -1544,9 +1546,11 @@ class ModuleSummaryIndex {
}
if (Edges.empty()) {
// Failed to find root - return an empty node
- return FunctionSummary::makeDummyFunctionSummary({});
+ return FunctionSummary::makeDummyFunctionSummary(
+ SmallVector<FunctionSummary::EdgeTy, 0>());
}
- auto CallGraphRoot = FunctionSummary::makeDummyFunctionSummary(Edges);
+ auto CallGraphRoot =
+ FunctionSummary::makeDummyFunctionSummary(std::move(Edges));
return CallGraphRoot;
}
@@ -1894,10 +1898,11 @@ template <> struct GraphTraits<ValueInfo> {
return P.first;
}
using ChildIteratorType =
- mapped_iterator<std::vector<FunctionSummary::EdgeTy>::iterator,
+ mapped_iterator<SmallVector<FunctionSummary::EdgeTy, 0>::iterator,
decltype(&valueInfoFromEdge)>;
- using ChildEdgeIteratorType = std::vector<FunctionSummary::EdgeTy>::iterator;
+ using ChildEdgeIteratorType =
+ SmallVector<FunctionSummary::EdgeTy, 0>::iterator;
static NodeRef getEntryNode(ValueInfo V) { return V; }
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
index 8bfdd69a0bafaa..902d1305c818ac 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
@@ -230,7 +230,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
FSum.CanAutoHide,
static_cast<GlobalValueSummary::ImportKind>(FSum.ImportType)),
/*NumInsts=*/0, FunctionSummary::FFlags{}, std::move(Refs),
- ArrayRef<FunctionSummary::EdgeTy>{}, std::move(FSum.TypeTests),
+ SmallVector<FunctionSummary::EdgeTy, 0>{}, std::move(FSum.TypeTests),
std::move(FSum.TypeTestAssumeVCalls),
std::move(FSum.TypeCheckedLoadVCalls),
std::move(FSum.TypeTestAssumeConstVCalls),
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 95ef97a23a686e..2d4961dade9db1 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -309,7 +309,7 @@ static void computeFunctionSummary(
// Map from callee ValueId to profile count. Used to accumulate profile
// counts for all static calls to a given callee.
MapVector<ValueInfo, CalleeInfo, DenseMap<ValueInfo, unsigned>,
- std::vector<std::pair<ValueInfo, CalleeInfo>>>
+ SmallVector<FunctionSummary::EdgeTy, 0>>
CallGraphEdges;
SetVector<ValueInfo, SmallVector<ValueInfo, 0>> RefEdges, LoadRefEdges,
StoreRefEdges;
@@ -964,7 +964,7 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
/* HasUnknownCall */ true,
/* MustBeUnreachable */ false},
SmallVector<ValueInfo, 0>{},
- ArrayRef<FunctionSummary::EdgeTy>{},
+ SmallVector<FunctionSummary::EdgeTy, 0>{},
ArrayRef<GlobalValue::GUID>{},
ArrayRef<FunctionSummary::VFuncId>{},
ArrayRef<FunctionSummary::VFuncId>{},
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 8747e15115cf61..66edf1e5a29573 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -9396,7 +9396,7 @@ bool LLParser::parseFunctionSummary(std::string Name, GlobalValue::GUID GUID,
/*Live=*/false, /*IsLocal=*/false, /*CanAutoHide=*/false,
GlobalValueSummary::Definition);
unsigned InstCount;
- std::vector<FunctionSummary::EdgeTy> Calls;
+ SmallVector<FunctionSummary::EdgeTy, 0> Calls;
FunctionSummary::TypeIdInfo TypeIdInfo;
std::vector<FunctionSummary::ParamAccess> ParamAccesses;
SmallVector<ValueInfo, 0> Refs;
@@ -9685,7 +9685,8 @@ bool LLParser::parseOptionalFFlags(FunctionSummary::FFlags &FFlags) {
/// Call ::= '(' 'callee' ':' GVReference
/// [( ',' 'hotness' ':' Hotness | ',' 'relbf' ':' UInt32 )]?
/// [ ',' 'tail' ]? ')'
-bool LLParser::parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls) {
+bool LLParser::parseOptionalCalls(
+ SmallVectorImpl<FunctionSummary::EdgeTy> &Calls) {
assert(Lex.getKind() == lltok::kw_calls);
Lex.Lex();
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 4d00b640c57be7..4faee1fb9ada22 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -986,10 +986,9 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase {
uint64_t Offset,
DenseMap<unsigned, GlobalValue::LinkageTypes> &ValueIdToLinkageMap);
SmallVector<ValueInfo, 0> makeRefList(ArrayRef<uint64_t> Record);
- std::vector<FunctionSummary::EdgeTy> makeCallList(ArrayRef<uint64_t> Record,
- bool IsOldProfileFormat,
- bool HasProfile,
- bool HasRelBF);
+ SmallVector<FunctionSummary::EdgeTy, 0>
+ makeCallList(ArrayRef<uint64_t> Record, bool IsOldProfileFormat,
+ bool HasProfile, bool HasRelBF);
Error parseEntireSummary(unsigned ID);
Error parseModuleStringTable();
void parseTypeIdCompatibleVtableSummaryRecord(ArrayRef<uint64_t> Record);
@@ -7378,11 +7377,11 @@ ModuleSummaryIndexBitcodeReader::makeRefList(ArrayRef<uint64_t> Record) {
return Ret;
}
-std::vector<FunctionSummary::EdgeTy>
+SmallVector<FunctionSummary::EdgeTy, 0>
ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef<uint64_t> Record,
bool IsOldProfileFormat,
bool HasProfile, bool HasRelBF) {
- std::vector<FunctionSummary::EdgeTy> Ret;
+ SmallVector<FunctionSummary::EdgeTy, 0> Ret;
// In the case of new profile formats, there are two Record entries per
// Edge. Otherwise, conservatively reserve up to Record.size.
if (!IsOldProfileFormat && (HasProfile || HasRelBF))
@@ -7670,7 +7669,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
ArrayRef<uint64_t>(Record).slice(RefListStartIndex, NumRefs));
bool HasProfile = (BitCode == bitc::FS_PERMODULE_PROFILE);
bool HasRelBF = (BitCode == bitc::FS_PERMODULE_RELBF);
- std::vector<FunctionSummary::EdgeTy> Calls = makeCallList(
+ SmallVector<FunctionSummary::EdgeTy, 0> Calls = makeCallList(
ArrayRef<uint64_t>(Record).slice(CallGraphEdgeStartIndex),
IsOldProfileFormat, HasProfile, HasRelBF);
setSpecialRefs(Refs, NumRORefs, NumWORefs);
@@ -7824,7 +7823,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
SmallVector<ValueInfo, 0> Refs = makeRefList(
ArrayRef<uint64_t>(Record).slice(RefListStartIndex, NumRefs));
bool HasProfile = (BitCode == bitc::FS_COMBINED_PROFILE);
- std::vector<FunctionSummary::EdgeTy> Edges = makeCallList(
+ SmallVector<FunctionSummary::EdgeTy, 0> Edges = makeCallList(
ArrayRef<uint64_t>(Record).slice(CallGraphEdgeStartIndex),
IsOldProfileFormat, HasProfile, false);
ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp
index a788e63d95a117..12a558b3bc1b12 100644
--- a/llvm/lib/IR/ModuleSummaryIndex.cpp
+++ b/llvm/lib/IR/ModuleSummaryIndex.cpp
@@ -37,7 +37,8 @@ static cl::opt<bool> ImportConstantsWithRefs(
constexpr uint32_t FunctionSummary::ParamAccess::RangeWidth;
FunctionSummary FunctionSummary::ExternalNode =
- FunctionSummary::makeDummyFunctionSummary({});
+ FunctionSummary::makeDummyFunctionSummary(
+ SmallVector<FunctionSummary::EdgeTy, 0>());
GlobalValue::VisibilityTypes ValueInfo::getELFVisibility() const {
bool HasProtected = false;
More information about the llvm-commits
mailing list