Skip to content

Commit d4ddf06

Browse files
[NFCI]Remove EntryCount from FunctionSummary and clean up surrounding synthetic count passes. (#107471)
The primary motivation is to remove `EntryCount` from `FunctionSummary`. This frees 8 bytes out of `sizeof(FunctionSummary)` (136 bytes as of 64498c5). While I'm at it, this PR clean up {SummaryBasedOptimizations, SyntheticCountsPropagation} since they were not used and there are no plans to further invest on them. With this patch, bitcode writer writes a placeholder 0 at the byte offset of `EntryCount` and bitcode reader can parse the function entry count at the correct byte offset. Added a TODO to stop writing `EntryCount` and bump bitcode version
1 parent 3a13c5a commit d4ddf06

27 files changed

+23
-567
lines changed

clang/docs/tools/clang-formatted-files.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5349,7 +5349,6 @@ llvm/include/llvm/IR/SSAContext.h
53495349
llvm/include/llvm/IR/StructuralHash.h
53505350
llvm/include/llvm/IR/TrackingMDRef.h
53515351
llvm/include/llvm/IR/UseListOrder.h
5352-
llvm/include/llvm/LTO/SummaryBasedOptimizations.h
53535352
llvm/include/llvm/MC/MCAsmInfoCOFF.h
53545353
llvm/include/llvm/MC/MCAsmInfoDarwin.h
53555354
llvm/include/llvm/MC/MCAsmInfoELF.h
@@ -5586,7 +5585,6 @@ llvm/include/llvm/Transforms/IPO/SampleProfile.h
55865585
llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
55875586
llvm/include/llvm/Transforms/IPO/SCCP.h
55885587
llvm/include/llvm/Transforms/IPO/StripSymbols.h
5589-
llvm/include/llvm/Transforms/IPO/SyntheticCountsPropagation.h
55905588
llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
55915589
llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
55925590
llvm/include/llvm/Transforms/Scalar/ADCE.h
@@ -6070,7 +6068,6 @@ llvm/lib/IR/SSAContext.cpp
60706068
llvm/lib/IR/Statepoint.cpp
60716069
llvm/lib/IR/StructuralHash.cpp
60726070
llvm/lib/IR/ValueSymbolTable.cpp
6073-
llvm/lib/LTO/SummaryBasedOptimizations.cpp
60746071
llvm/lib/MC/MCAsmInfoCOFF.cpp
60756072
llvm/lib/MC/MCAsmInfoELF.cpp
60766073
llvm/lib/MC/MCAsmInfoGOFF.cpp
@@ -6861,7 +6858,6 @@ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
68616858
llvm/lib/Transforms/IPO/SampleContextTracker.cpp
68626859
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
68636860
llvm/lib/Transforms/IPO/StripDeadPrototypes.cpp
6864-
llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp
68656861
llvm/lib/Transforms/ObjCARC/BlotMapVector.h
68666862
llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp
68676863
llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -858,9 +858,8 @@ class FunctionSummary : public GlobalValueSummary {
858858
GlobalValue::DefaultVisibility,
859859
/*NotEligibleToImport=*/true, /*Live=*/true, /*IsLocal=*/false,
860860
/*CanAutoHide=*/false, GlobalValueSummary::ImportKind::Definition),
861-
/*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0,
862-
SmallVector<ValueInfo, 0>(), std::move(Edges),
863-
std::vector<GlobalValue::GUID>(),
861+
/*NumInsts=*/0, FunctionSummary::FFlags{}, SmallVector<ValueInfo, 0>(),
862+
std::move(Edges), std::vector<GlobalValue::GUID>(),
864863
std::vector<FunctionSummary::VFuncId>(),
865864
std::vector<FunctionSummary::VFuncId>(),
866865
std::vector<FunctionSummary::ConstVCall>(),
@@ -880,11 +879,6 @@ class FunctionSummary : public GlobalValueSummary {
880879
/// Function summary specific flags.
881880
FFlags FunFlags;
882881

883-
/// The synthesized entry count of the function.
884-
/// This is only populated during ThinLink phase and remains unused while
885-
/// generating per-module summaries.
886-
uint64_t EntryCount = 0;
887-
888882
/// List of <CalleeValueInfo, CalleeInfo> call edge pairs from this function.
889883
std::vector<EdgeTy> CallGraphEdgeList;
890884

@@ -915,7 +909,7 @@ class FunctionSummary : public GlobalValueSummary {
915909

916910
public:
917911
FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags,
918-
uint64_t EntryCount, SmallVectorImpl<ValueInfo> &&Refs,
912+
SmallVectorImpl<ValueInfo> &&Refs,
919913
std::vector<EdgeTy> CGEdges,
920914
std::vector<GlobalValue::GUID> TypeTests,
921915
std::vector<VFuncId> TypeTestAssumeVCalls,
@@ -925,7 +919,7 @@ class FunctionSummary : public GlobalValueSummary {
925919
std::vector<ParamAccess> Params, CallsitesTy CallsiteList,
926920
AllocsTy AllocList)
927921
: GlobalValueSummary(FunctionKind, Flags, std::move(Refs)),
928-
InstCount(NumInsts), FunFlags(FunFlags), EntryCount(EntryCount),
922+
InstCount(NumInsts), FunFlags(FunFlags),
929923
CallGraphEdgeList(std::move(CGEdges)) {
930924
if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
931925
!TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
@@ -960,12 +954,6 @@ class FunctionSummary : public GlobalValueSummary {
960954
/// Get the instruction count recorded for this function.
961955
unsigned instCount() const { return InstCount; }
962956

963-
/// Get the synthetic entry count for this function.
964-
uint64_t entryCount() const { return EntryCount; }
965-
966-
/// Set the synthetic entry count for this function.
967-
void setEntryCount(uint64_t EC) { EntryCount = EC; }
968-
969957
/// Return the list of <CalleeValueInfo, CalleeInfo> pairs.
970958
ArrayRef<EdgeTy> calls() const { return CallGraphEdgeList; }
971959

@@ -1587,9 +1575,6 @@ class ModuleSummaryIndex {
15871575
return WithAttributePropagation && GVS->maybeWriteOnly();
15881576
}
15891577

1590-
bool hasSyntheticEntryCounts() const { return HasSyntheticEntryCounts; }
1591-
void setHasSyntheticEntryCounts() { HasSyntheticEntryCounts = true; }
1592-
15931578
bool withSupportsHotColdNew() const { return WithSupportsHotColdNew; }
15941579
void setWithSupportsHotColdNew() { WithSupportsHotColdNew = true; }
15951580

llvm/include/llvm/IR/ModuleSummaryIndexYAML.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
229229
FSum.NotEligibleToImport, FSum.Live, FSum.IsLocal,
230230
FSum.CanAutoHide,
231231
static_cast<GlobalValueSummary::ImportKind>(FSum.ImportType)),
232-
/*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0,
233-
std::move(Refs), ArrayRef<FunctionSummary::EdgeTy>{},
234-
std::move(FSum.TypeTests), std::move(FSum.TypeTestAssumeVCalls),
232+
/*NumInsts=*/0, FunctionSummary::FFlags{}, std::move(Refs),
233+
ArrayRef<FunctionSummary::EdgeTy>{}, std::move(FSum.TypeTests),
234+
std::move(FSum.TypeTestAssumeVCalls),
235235
std::move(FSum.TypeCheckedLoadVCalls),
236236
std::move(FSum.TypeTestAssumeConstVCalls),
237237
std::move(FSum.TypeCheckedLoadConstVCalls),

llvm/include/llvm/LTO/SummaryBasedOptimizations.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

llvm/include/llvm/Transforms/IPO/SyntheticCountsPropagation.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,9 @@ static void computeFunctionSummary(
673673
if (auto *SSI = GetSSICallback(F))
674674
ParamAccesses = SSI->getParamAccesses(Index);
675675
auto FuncSummary = std::make_unique<FunctionSummary>(
676-
Flags, NumInsts, FunFlags, /*EntryCount=*/0, std::move(Refs),
677-
CallGraphEdges.takeVector(), TypeTests.takeVector(),
678-
TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(),
676+
Flags, NumInsts, FunFlags, std::move(Refs), CallGraphEdges.takeVector(),
677+
TypeTests.takeVector(), TypeTestAssumeVCalls.takeVector(),
678+
TypeCheckedLoadVCalls.takeVector(),
679679
TypeTestAssumeConstVCalls.takeVector(),
680680
TypeCheckedLoadConstVCalls.takeVector(), std::move(ParamAccesses),
681681
std::move(Callsites), std::move(Allocs));
@@ -963,7 +963,7 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
963963
/* MayThrow */ true,
964964
/* HasUnknownCall */ true,
965965
/* MustBeUnreachable */ false},
966-
/*EntryCount=*/0, SmallVector<ValueInfo, 0>{},
966+
SmallVector<ValueInfo, 0>{},
967967
ArrayRef<FunctionSummary::EdgeTy>{},
968968
ArrayRef<GlobalValue::GUID>{},
969969
ArrayRef<FunctionSummary::VFuncId>{},

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9453,8 +9453,8 @@ bool LLParser::parseFunctionSummary(std::string Name, GlobalValue::GUID GUID,
94539453
return true;
94549454

94559455
auto FS = std::make_unique<FunctionSummary>(
9456-
GVFlags, InstCount, FFlags, /*EntryCount=*/0, std::move(Refs),
9457-
std::move(Calls), std::move(TypeIdInfo.TypeTests),
9456+
GVFlags, InstCount, FFlags, std::move(Refs), std::move(Calls),
9457+
std::move(TypeIdInfo.TypeTests),
94589458
std::move(TypeIdInfo.TypeTestAssumeVCalls),
94599459
std::move(TypeIdInfo.TypeCheckedLoadVCalls),
94609460
std::move(TypeIdInfo.TypeTestAssumeConstVCalls),

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7686,8 +7686,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
76867686
PendingAllocs.clear();
76877687
}
76887688
auto FS = std::make_unique<FunctionSummary>(
7689-
Flags, InstCount, getDecodedFFlags(RawFunFlags), /*EntryCount=*/0,
7690-
std::move(Refs), std::move(Calls), std::move(PendingTypeTests),
7689+
Flags, InstCount, getDecodedFFlags(RawFunFlags), std::move(Refs),
7690+
std::move(Calls), std::move(PendingTypeTests),
76917691
std::move(PendingTypeTestAssumeVCalls),
76927692
std::move(PendingTypeCheckedLoadVCalls),
76937693
std::move(PendingTypeTestAssumeConstVCalls),
@@ -7832,8 +7832,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
78327832
ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
78337833
setSpecialRefs(Refs, NumRORefs, NumWORefs);
78347834
auto FS = std::make_unique<FunctionSummary>(
7835-
Flags, InstCount, getDecodedFFlags(RawFunFlags), EntryCount,
7836-
std::move(Refs), std::move(Edges), std::move(PendingTypeTests),
7835+
Flags, InstCount, getDecodedFFlags(RawFunFlags), std::move(Refs),
7836+
std::move(Edges), std::move(PendingTypeTests),
78377837
std::move(PendingTypeTestAssumeVCalls),
78387838
std::move(PendingTypeCheckedLoadVCalls),
78397839
std::move(PendingTypeTestAssumeConstVCalls),

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4740,7 +4740,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
47404740
getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDecl(FS)));
47414741
NameVals.push_back(FS->instCount());
47424742
NameVals.push_back(getEncodedFFlags(FS->fflags()));
4743-
NameVals.push_back(FS->entryCount());
4743+
// TODO: Stop writing entry count and bump bitcode version.
4744+
NameVals.push_back(0 /* EntryCount */);
47444745

47454746
// Fill in below
47464747
NameVals.push_back(0); // numrefs

llvm/lib/IR/ModuleSummaryIndex.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,11 @@ constexpr uint64_t ModuleSummaryIndex::BitcodeSummaryVersion;
9191

9292
uint64_t ModuleSummaryIndex::getFlags() const {
9393
uint64_t Flags = 0;
94+
// Flags & 0x4 is reserved. DO NOT REUSE.
9495
if (withGlobalValueDeadStripping())
9596
Flags |= 0x1;
9697
if (skipModuleByDistributedBackend())
9798
Flags |= 0x2;
98-
if (hasSyntheticEntryCounts())
99-
Flags |= 0x4;
10099
if (enableSplitLTOUnit())
101100
Flags |= 0x8;
102101
if (partiallySplitLTOUnits())
@@ -124,10 +123,7 @@ void ModuleSummaryIndex::setFlags(uint64_t Flags) {
124123
// Set on combined index only.
125124
if (Flags & 0x2)
126125
setSkipModuleByDistributedBackend();
127-
// 1 bit: HasSyntheticEntryCounts flag.
128-
// Set on combined index only.
129-
if (Flags & 0x4)
130-
setHasSyntheticEntryCounts();
126+
// Flags & 0x4 is reserved. DO NOT REUSE.
131127
// 1 bit: DisableSplitLTOUnit flag.
132128
// Set on per module indexes. It is up to the client to validate
133129
// the consistency of this flag across modules being linked.

llvm/lib/LTO/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ add_llvm_component_library(LLVMLTO
33
LTOBackend.cpp
44
LTOModule.cpp
55
LTOCodeGenerator.cpp
6-
SummaryBasedOptimizations.cpp
76
UpdateCompilerUsed.cpp
87
ThinLTOCodeGenerator.cpp
98

llvm/lib/LTO/LTO.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "llvm/IR/Metadata.h"
3333
#include "llvm/IR/RuntimeLibcalls.h"
3434
#include "llvm/LTO/LTOBackend.h"
35-
#include "llvm/LTO/SummaryBasedOptimizations.h"
3635
#include "llvm/Linker/IRMover.h"
3736
#include "llvm/MC/TargetRegistry.h"
3837
#include "llvm/Object/IRObjectFile.h"
@@ -1693,9 +1692,6 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
16931692
if (!ModuleToDefinedGVSummaries.count(Mod.first))
16941693
ModuleToDefinedGVSummaries.try_emplace(Mod.first);
16951694

1696-
// Synthesize entry counts for functions in the CombinedIndex.
1697-
computeSyntheticCounts(ThinLTO.CombinedIndex);
1698-
16991695
FunctionImporter::ImportListsTy ImportLists(ThinLTO.ModuleMap.size());
17001696
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(
17011697
ThinLTO.ModuleMap.size());

llvm/lib/LTO/SummaryBasedOptimizations.cpp

Lines changed: 0 additions & 88 deletions
This file was deleted.

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727
#include "llvm/Config/llvm-config.h"
2828
#include "llvm/IR/DebugInfo.h"
2929
#include "llvm/IR/DiagnosticPrinter.h"
30-
#include "llvm/IR/LegacyPassManager.h"
3130
#include "llvm/IR/LLVMContext.h"
3231
#include "llvm/IR/LLVMRemarkStreamer.h"
32+
#include "llvm/IR/LegacyPassManager.h"
3333
#include "llvm/IR/Mangler.h"
3434
#include "llvm/IR/PassTimingInfo.h"
3535
#include "llvm/IR/Verifier.h"
3636
#include "llvm/IRReader/IRReader.h"
3737
#include "llvm/LTO/LTO.h"
38-
#include "llvm/LTO/SummaryBasedOptimizations.h"
3938
#include "llvm/MC/TargetRegistry.h"
4039
#include "llvm/Object/IRObjectFile.h"
4140
#include "llvm/Passes/PassBuilder.h"
@@ -1042,9 +1041,6 @@ void ThinLTOCodeGenerator::run() {
10421041
// Compute "dead" symbols, we don't want to import/export these!
10431042
computeDeadSymbolsInIndex(*Index, GUIDPreservedSymbols);
10441043

1045-
// Synthesize entry counts for functions in the combined index.
1046-
computeSyntheticCounts(*Index);
1047-
10481044
// Currently there is no support for enabling whole program visibility via a
10491045
// linker option in the old LTO API, but this call allows it to be specified
10501046
// via the internal option. Must be done before WPD below.

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@
180180
#include "llvm/Transforms/IPO/SampleProfileProbe.h"
181181
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
182182
#include "llvm/Transforms/IPO/StripSymbols.h"
183-
#include "llvm/Transforms/IPO/SyntheticCountsPropagation.h"
184183
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
185184
#include "llvm/Transforms/InstCombine/InstCombine.h"
186185
#include "llvm/Transforms/Instrumentation.h"

0 commit comments

Comments
 (0)