[clang] [llvm] [NFCI]Remove EntryCount from FunctionSummary and clean up surrounding synthetic count passes. (PR #107471)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 5 16:04:14 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Mingming Liu (minglotus-6)

<details>
<summary>Changes</summary>

The primary motivation is to remove `EntryCount` from `FunctionSummary`. This frees 8 bytes out of `sizeof(FunctionSummary)` (136 byte as of https://github.com/llvm/llvm-project/commit/64498c54831bed9cf069e0923b9b73678c6451d8).

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


---

Patch is 37.45 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/107471.diff


26 Files Affected:

- (modified) clang/docs/tools/clang-formatted-files.txt (-4) 
- (modified) llvm/include/llvm/IR/ModuleSummaryIndex.h (+4-20) 
- (modified) llvm/include/llvm/IR/ModuleSummaryIndexYAML.h (+1-1) 
- (removed) llvm/include/llvm/LTO/SummaryBasedOptimizations.h (-18) 
- (removed) llvm/include/llvm/Transforms/IPO/SyntheticCountsPropagation.h (-23) 
- (modified) llvm/lib/Analysis/ModuleSummaryAnalysis.cpp (+4-5) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+2-2) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+4-4) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+2-1) 
- (modified) llvm/lib/IR/ModuleSummaryIndex.cpp (+2-6) 
- (modified) llvm/lib/LTO/CMakeLists.txt (-1) 
- (modified) llvm/lib/LTO/LTO.cpp (-4) 
- (removed) llvm/lib/LTO/SummaryBasedOptimizations.cpp (-88) 
- (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (-4) 
- (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (-9) 
- (modified) llvm/lib/Passes/PassRegistry.def (-1) 
- (modified) llvm/lib/Transforms/IPO/CMakeLists.txt (-1) 
- (removed) llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp (-139) 
- (modified) llvm/lib/Transforms/Utils/FunctionImportUtils.cpp (+1-17) 
- (removed) llvm/test/Bitcode/thinlto-synthetic-count-flag.ll (-21) 
- (removed) llvm/test/ThinLTO/X86/function_entry_count.ll (-45) 
- (removed) llvm/test/Transforms/SyntheticCountsPropagation/initial.ll (-79) 
- (removed) llvm/test/Transforms/SyntheticCountsPropagation/prop.ll (-50) 
- (removed) llvm/test/Transforms/SyntheticCountsPropagation/scc.ll (-19) 
- (modified) llvm/utils/gn/secondary/llvm/lib/LTO/BUILD.gn (-1) 
- (modified) llvm/utils/gn/secondary/llvm/lib/Transforms/IPO/BUILD.gn (-1) 


``````````diff
diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt
index fc07357986d989..48ded9c7545547 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -5349,7 +5349,6 @@ llvm/include/llvm/IR/SSAContext.h
 llvm/include/llvm/IR/StructuralHash.h
 llvm/include/llvm/IR/TrackingMDRef.h
 llvm/include/llvm/IR/UseListOrder.h
-llvm/include/llvm/LTO/SummaryBasedOptimizations.h
 llvm/include/llvm/MC/MCAsmInfoCOFF.h
 llvm/include/llvm/MC/MCAsmInfoDarwin.h
 llvm/include/llvm/MC/MCAsmInfoELF.h
@@ -5586,7 +5585,6 @@ llvm/include/llvm/Transforms/IPO/SampleProfile.h
 llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
 llvm/include/llvm/Transforms/IPO/SCCP.h
 llvm/include/llvm/Transforms/IPO/StripSymbols.h
-llvm/include/llvm/Transforms/IPO/SyntheticCountsPropagation.h
 llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
 llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
 llvm/include/llvm/Transforms/Scalar/ADCE.h
@@ -6070,7 +6068,6 @@ llvm/lib/IR/SSAContext.cpp
 llvm/lib/IR/Statepoint.cpp
 llvm/lib/IR/StructuralHash.cpp
 llvm/lib/IR/ValueSymbolTable.cpp
-llvm/lib/LTO/SummaryBasedOptimizations.cpp
 llvm/lib/MC/MCAsmInfoCOFF.cpp
 llvm/lib/MC/MCAsmInfoELF.cpp
 llvm/lib/MC/MCAsmInfoGOFF.cpp
@@ -6861,7 +6858,6 @@ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
 llvm/lib/Transforms/IPO/SampleContextTracker.cpp
 llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
 llvm/lib/Transforms/IPO/StripDeadPrototypes.cpp
-llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp
 llvm/lib/Transforms/ObjCARC/BlotMapVector.h
 llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp
 llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 6d39150a03bfd5..eae04f4eadcccd 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -856,9 +856,8 @@ class FunctionSummary : public GlobalValueSummary {
             GlobalValue::DefaultVisibility,
             /*NotEligibleToImport=*/true, /*Live=*/true, /*IsLocal=*/false,
             /*CanAutoHide=*/false, GlobalValueSummary::ImportKind::Definition),
-        /*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0,
-        std::vector<ValueInfo>(), std::move(Edges),
-        std::vector<GlobalValue::GUID>(),
+        /*NumInsts=*/0, FunctionSummary::FFlags{}, std::vector<ValueInfo>(),
+        std::move(Edges), std::vector<GlobalValue::GUID>(),
         std::vector<FunctionSummary::VFuncId>(),
         std::vector<FunctionSummary::VFuncId>(),
         std::vector<FunctionSummary::ConstVCall>(),
@@ -878,11 +877,6 @@ class FunctionSummary : public GlobalValueSummary {
   /// Function summary specific flags.
   FFlags FunFlags;
 
-  /// The synthesized entry count of the function.
-  /// This is only populated during ThinLink phase and remains unused while
-  /// generating per-module summaries.
-  uint64_t EntryCount = 0;
-
   /// List of <CalleeValueInfo, CalleeInfo> call edge pairs from this function.
   std::vector<EdgeTy> CallGraphEdgeList;
 
@@ -913,8 +907,7 @@ class FunctionSummary : public GlobalValueSummary {
 
 public:
   FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags,
-                  uint64_t EntryCount, std::vector<ValueInfo> Refs,
-                  std::vector<EdgeTy> CGEdges,
+                  std::vector<ValueInfo> Refs, std::vector<EdgeTy> CGEdges,
                   std::vector<GlobalValue::GUID> TypeTests,
                   std::vector<VFuncId> TypeTestAssumeVCalls,
                   std::vector<VFuncId> TypeCheckedLoadVCalls,
@@ -923,7 +916,7 @@ class FunctionSummary : public GlobalValueSummary {
                   std::vector<ParamAccess> Params, CallsitesTy CallsiteList,
                   AllocsTy AllocList)
       : GlobalValueSummary(FunctionKind, Flags, std::move(Refs)),
-        InstCount(NumInsts), FunFlags(FunFlags), EntryCount(EntryCount),
+        InstCount(NumInsts), FunFlags(FunFlags),
         CallGraphEdgeList(std::move(CGEdges)) {
     if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
         !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
@@ -958,12 +951,6 @@ class FunctionSummary : public GlobalValueSummary {
   /// Get the instruction count recorded for this function.
   unsigned instCount() const { return InstCount; }
 
-  /// Get the synthetic entry count for this function.
-  uint64_t entryCount() const { return EntryCount; }
-
-  /// Set the synthetic entry count for this function.
-  void setEntryCount(uint64_t EC) { EntryCount = EC; }
-
   /// Return the list of <CalleeValueInfo, CalleeInfo> pairs.
   ArrayRef<EdgeTy> calls() const { return CallGraphEdgeList; }
 
@@ -1585,9 +1572,6 @@ class ModuleSummaryIndex {
     return WithAttributePropagation && GVS->maybeWriteOnly();
   }
 
-  bool hasSyntheticEntryCounts() const { return HasSyntheticEntryCounts; }
-  void setHasSyntheticEntryCounts() { HasSyntheticEntryCounts = true; }
-
   bool withSupportsHotColdNew() const { return WithSupportsHotColdNew; }
   void setWithSupportsHotColdNew() { WithSupportsHotColdNew = true; }
 
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
index 6cc533f043a517..3ce929afdb1ea6 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
@@ -229,7 +229,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
               FSum.NotEligibleToImport, FSum.Live, FSum.IsLocal,
               FSum.CanAutoHide,
               static_cast<GlobalValueSummary::ImportKind>(FSum.ImportType)),
-          /*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0, Refs,
+          /*NumInsts=*/0, FunctionSummary::FFlags{}, Refs,
           ArrayRef<FunctionSummary::EdgeTy>{}, std::move(FSum.TypeTests),
           std::move(FSum.TypeTestAssumeVCalls),
           std::move(FSum.TypeCheckedLoadVCalls),
diff --git a/llvm/include/llvm/LTO/SummaryBasedOptimizations.h b/llvm/include/llvm/LTO/SummaryBasedOptimizations.h
deleted file mode 100644
index 508ab2587ac56a..00000000000000
--- a/llvm/include/llvm/LTO/SummaryBasedOptimizations.h
+++ /dev/null
@@ -1,18 +0,0 @@
-//=- llvm/LTO/SummaryBasedOptimizations.h -Link time optimizations-*- C++ -*-=//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LTO_SUMMARYBASEDOPTIMIZATIONS_H
-#define LLVM_LTO_SUMMARYBASEDOPTIMIZATIONS_H
-namespace llvm {
-class ModuleSummaryIndex;
-
-/// Compute synthetic function entry counts.
-void computeSyntheticCounts(ModuleSummaryIndex &Index);
-
-} // namespace llvm
-#endif
diff --git a/llvm/include/llvm/Transforms/IPO/SyntheticCountsPropagation.h b/llvm/include/llvm/Transforms/IPO/SyntheticCountsPropagation.h
deleted file mode 100644
index 5338ac9b0ebc57..00000000000000
--- a/llvm/include/llvm/Transforms/IPO/SyntheticCountsPropagation.h
+++ /dev/null
@@ -1,23 +0,0 @@
-//=- SyntheticCountsPropagation.h - Propagate function counts -----*- C++ -*-=//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TRANSFORMS_IPO_SYNTHETICCOUNTSPROPAGATION_H
-#define LLVM_TRANSFORMS_IPO_SYNTHETICCOUNTSPROPAGATION_H
-
-#include "llvm/IR/PassManager.h"
-
-namespace llvm {
-class Module;
-
-class SyntheticCountsPropagation
-    : public PassInfoMixin<SyntheticCountsPropagation> {
-public:
-  PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
-};
-} // namespace llvm
-#endif
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index e9490ccba82157..bd232572dac86c 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -671,9 +671,9 @@ static void computeFunctionSummary(
   if (auto *SSI = GetSSICallback(F))
     ParamAccesses = SSI->getParamAccesses(Index);
   auto FuncSummary = std::make_unique<FunctionSummary>(
-      Flags, NumInsts, FunFlags, /*EntryCount=*/0, std::move(Refs),
-      CallGraphEdges.takeVector(), TypeTests.takeVector(),
-      TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(),
+      Flags, NumInsts, FunFlags, std::move(Refs), CallGraphEdges.takeVector(),
+      TypeTests.takeVector(), TypeTestAssumeVCalls.takeVector(),
+      TypeCheckedLoadVCalls.takeVector(),
       TypeTestAssumeConstVCalls.takeVector(),
       TypeCheckedLoadConstVCalls.takeVector(), std::move(ParamAccesses),
       std::move(Callsites), std::move(Allocs));
@@ -961,8 +961,7 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
                         /* MayThrow */ true,
                         /* HasUnknownCall */ true,
                         /* MustBeUnreachable */ false},
-                    /*EntryCount=*/0, ArrayRef<ValueInfo>{},
-                    ArrayRef<FunctionSummary::EdgeTy>{},
+                    ArrayRef<ValueInfo>{}, ArrayRef<FunctionSummary::EdgeTy>{},
                     ArrayRef<GlobalValue::GUID>{},
                     ArrayRef<FunctionSummary::VFuncId>{},
                     ArrayRef<FunctionSummary::VFuncId>{},
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 93dc2bd241581b..4a3d052149a56e 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -9447,8 +9447,8 @@ bool LLParser::parseFunctionSummary(std::string Name, GlobalValue::GUID GUID,
     return true;
 
   auto FS = std::make_unique<FunctionSummary>(
-      GVFlags, InstCount, FFlags, /*EntryCount=*/0, std::move(Refs),
-      std::move(Calls), std::move(TypeIdInfo.TypeTests),
+      GVFlags, InstCount, FFlags, std::move(Refs), std::move(Calls),
+      std::move(TypeIdInfo.TypeTests),
       std::move(TypeIdInfo.TypeTestAssumeVCalls),
       std::move(TypeIdInfo.TypeCheckedLoadVCalls),
       std::move(TypeIdInfo.TypeTestAssumeConstVCalls),
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1cd9ec6b8fca20..2b53ee5698127b 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -7682,8 +7682,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
         PendingAllocs.clear();
       }
       auto FS = std::make_unique<FunctionSummary>(
-          Flags, InstCount, getDecodedFFlags(RawFunFlags), /*EntryCount=*/0,
-          std::move(Refs), std::move(Calls), std::move(PendingTypeTests),
+          Flags, InstCount, getDecodedFFlags(RawFunFlags), std::move(Refs),
+          std::move(Calls), std::move(PendingTypeTests),
           std::move(PendingTypeTestAssumeVCalls),
           std::move(PendingTypeCheckedLoadVCalls),
           std::move(PendingTypeTestAssumeConstVCalls),
@@ -7828,8 +7828,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
       ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
       setSpecialRefs(Refs, NumRORefs, NumWORefs);
       auto FS = std::make_unique<FunctionSummary>(
-          Flags, InstCount, getDecodedFFlags(RawFunFlags), EntryCount,
-          std::move(Refs), std::move(Edges), std::move(PendingTypeTests),
+          Flags, InstCount, getDecodedFFlags(RawFunFlags), std::move(Refs),
+          std::move(Edges), std::move(PendingTypeTests),
           std::move(PendingTypeTestAssumeVCalls),
           std::move(PendingTypeCheckedLoadVCalls),
           std::move(PendingTypeTestAssumeConstVCalls),
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 26fd02b3e1a043..9b630de2ef11e3 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4736,7 +4736,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
         getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDecl(FS)));
     NameVals.push_back(FS->instCount());
     NameVals.push_back(getEncodedFFlags(FS->fflags()));
-    NameVals.push_back(FS->entryCount());
+    // TODO: Stop writing entry count and bump bitcode version.
+    NameVals.push_back(0 /* EntryCount */);
 
     // Fill in below
     NameVals.push_back(0); // numrefs
diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp
index 6713d32fb787ce..a788e63d95a117 100644
--- a/llvm/lib/IR/ModuleSummaryIndex.cpp
+++ b/llvm/lib/IR/ModuleSummaryIndex.cpp
@@ -91,12 +91,11 @@ constexpr uint64_t ModuleSummaryIndex::BitcodeSummaryVersion;
 
 uint64_t ModuleSummaryIndex::getFlags() const {
   uint64_t Flags = 0;
+  // Flags & 0x4 is reserved. DO NOT REUSE.
   if (withGlobalValueDeadStripping())
     Flags |= 0x1;
   if (skipModuleByDistributedBackend())
     Flags |= 0x2;
-  if (hasSyntheticEntryCounts())
-    Flags |= 0x4;
   if (enableSplitLTOUnit())
     Flags |= 0x8;
   if (partiallySplitLTOUnits())
@@ -124,10 +123,7 @@ void ModuleSummaryIndex::setFlags(uint64_t Flags) {
   // Set on combined index only.
   if (Flags & 0x2)
     setSkipModuleByDistributedBackend();
-  // 1 bit: HasSyntheticEntryCounts flag.
-  // Set on combined index only.
-  if (Flags & 0x4)
-    setHasSyntheticEntryCounts();
+  // Flags & 0x4 is reserved. DO NOT REUSE.
   // 1 bit: DisableSplitLTOUnit flag.
   // Set on per module indexes. It is up to the client to validate
   // the consistency of this flag across modules being linked.
diff --git a/llvm/lib/LTO/CMakeLists.txt b/llvm/lib/LTO/CMakeLists.txt
index 9ba7698bc9954b..69ff08e1f374c4 100644
--- a/llvm/lib/LTO/CMakeLists.txt
+++ b/llvm/lib/LTO/CMakeLists.txt
@@ -3,7 +3,6 @@ add_llvm_component_library(LLVMLTO
   LTOBackend.cpp
   LTOModule.cpp
   LTOCodeGenerator.cpp
-  SummaryBasedOptimizations.cpp
   UpdateCompilerUsed.cpp
   ThinLTOCodeGenerator.cpp
 
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index b1aa89ac978134..68072563cb33d6 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -32,7 +32,6 @@
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/RuntimeLibcalls.h"
 #include "llvm/LTO/LTOBackend.h"
-#include "llvm/LTO/SummaryBasedOptimizations.h"
 #include "llvm/Linker/IRMover.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Object/IRObjectFile.h"
@@ -1693,9 +1692,6 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
     if (!ModuleToDefinedGVSummaries.count(Mod.first))
       ModuleToDefinedGVSummaries.try_emplace(Mod.first);
 
-  // Synthesize entry counts for functions in the CombinedIndex.
-  computeSyntheticCounts(ThinLTO.CombinedIndex);
-
   FunctionImporter::ImportListsTy ImportLists(ThinLTO.ModuleMap.size());
   DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(
       ThinLTO.ModuleMap.size());
diff --git a/llvm/lib/LTO/SummaryBasedOptimizations.cpp b/llvm/lib/LTO/SummaryBasedOptimizations.cpp
deleted file mode 100644
index bd3565771c293c..00000000000000
--- a/llvm/lib/LTO/SummaryBasedOptimizations.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-//==-SummaryBasedOptimizations.cpp - Optimizations based on ThinLTO summary-==//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements optimizations that are based on the module summaries.
-// These optimizations are performed during the thinlink phase of the
-// compilation.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/LTO/SummaryBasedOptimizations.h"
-#include "llvm/Analysis/SyntheticCountsUtils.h"
-#include "llvm/IR/ModuleSummaryIndex.h"
-#include "llvm/Support/CommandLine.h"
-
-using namespace llvm;
-
-static cl::opt<bool> ThinLTOSynthesizeEntryCounts(
-    "thinlto-synthesize-entry-counts", cl::init(false), cl::Hidden,
-    cl::desc("Synthesize entry counts based on the summary"));
-
-namespace llvm {
-extern cl::opt<int> InitialSyntheticCount;
-}
-
-static void initializeCounts(ModuleSummaryIndex &Index) {
-  auto Root = Index.calculateCallGraphRoot();
-  // Root is a fake node. All its successors are the actual roots of the
-  // callgraph.
-  // FIXME: This initializes the entry counts of only the root nodes. This makes
-  // sense when compiling a binary with ThinLTO, but for libraries any of the
-  // non-root nodes could be called from outside.
-  for (auto &C : Root.calls()) {
-    auto &V = C.first;
-    for (auto &GVS : V.getSummaryList()) {
-      auto S = GVS.get()->getBaseObject();
-      auto *F = cast<FunctionSummary>(S);
-      F->setEntryCount(InitialSyntheticCount);
-    }
-  }
-}
-
-void llvm::computeSyntheticCounts(ModuleSummaryIndex &Index) {
-  if (!ThinLTOSynthesizeEntryCounts)
-    return;
-
-  using Scaled64 = ScaledNumber<uint64_t>;
-  initializeCounts(Index);
-  auto GetCallSiteRelFreq = [](FunctionSummary::EdgeTy &Edge) {
-    return Scaled64(Edge.second.RelBlockFreq, -CalleeInfo::ScaleShift);
-  };
-  auto GetEntryCount = [](ValueInfo V) {
-    if (V.getSummaryList().size()) {
-      auto S = V.getSummaryList().front()->getBaseObject();
-      auto *F = cast<FunctionSummary>(S);
-      return F->entryCount();
-    } else {
-      return UINT64_C(0);
-    }
-  };
-  auto AddToEntryCount = [](ValueInfo V, Scaled64 New) {
-    if (!V.getSummaryList().size())
-      return;
-    for (auto &GVS : V.getSummaryList()) {
-      auto S = GVS.get()->getBaseObject();
-      auto *F = cast<FunctionSummary>(S);
-      F->setEntryCount(
-          SaturatingAdd(F->entryCount(), New.template toInt<uint64_t>()));
-    }
-  };
-
-  auto GetProfileCount = [&](ValueInfo V, FunctionSummary::EdgeTy &Edge) {
-    auto RelFreq = GetCallSiteRelFreq(Edge);
-    Scaled64 EC(GetEntryCount(V), 0);
-    return RelFreq * EC;
-  };
-  // After initializing the counts in initializeCounts above, the counts have to
-  // be propagated across the combined callgraph.
-  // SyntheticCountsUtils::propagate takes care of this propagation on any
-  // callgraph that specialized GraphTraits.
-  SyntheticCountsUtils<ModuleSummaryIndex *>::propagate(&Index, GetProfileCount,
-                                                        AddToEntryCount);
-  Index.setHasSyntheticEntryCounts();
-}
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 9d5a62fe10c8d7..7454b30bea2cb6 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -35,7 +35,6 @@
 #include "llvm/IR/Verifier.h"
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/LTO/LTO.h"
-#include "llvm/LTO/SummaryBasedOptimizations.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Object/IRObjectFile.h"
 #include "llvm/Passes/PassBuilder.h"
@@ -1042,9 +1041,6 @@ void ThinLTOCodeGenerator::run() {
   // Compute "dead" symbols, we don't want to import/export these!
   computeDeadSymbolsInIndex(*Index, GUIDPreservedSymbols);
 
-  // Synthesize entry counts for functions in the combined index.
-  computeSyntheticCounts(*Index);
-
   // Currently there is no support for enabling whole program visibility via a
   // linker option in the old LTO API, but this call allows it to be specified
   // via the internal option. Must be done before WPD below.
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 1fd7ef929c87d5..f344afc9b87922 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -154,11 +154,6 @@ static cl::opt<InliningAdvisorMode> UseInlineAdvisor(
                clEnumValN(InliningAdvisorMode::Release, "release",
                           "Use release mode (AOT-compiled model)")));
 
-static cl::opt<bool> EnableSyntheticCounts(
-    "enable-npm-synthetic-counts", cl::Hidden,
-    cl::desc("Run synthetic function entry count generation "
-             "pass"));
-
 /// Flag to enable inline deferral during PGO.
 static cl::...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/107471


More information about the cfe-commits mailing list