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

Mingming Liu via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 5 16:06:31 PDT 2024


https://github.com/minglotus-6 updated https://github.com/llvm/llvm-project/pull/107471

>From a18e042a0d03321d3ffca9ede92e976343a1b4c7 Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Thu, 5 Sep 2024 14:36:28 -0700
Subject: [PATCH 1/4] [NFCI]Clean up synthetic count

---
 clang/docs/tools/clang-formatted-files.txt    |   4 -
 llvm/include/llvm/IR/ModuleSummaryIndex.h     |  21 +--
 llvm/include/llvm/IR/ModuleSummaryIndexYAML.h |   2 +-
 .../llvm/LTO/SummaryBasedOptimizations.h      |  18 ---
 .../IPO/SyntheticCountsPropagation.h          |  23 ---
 llvm/lib/Analysis/ModuleSummaryAnalysis.cpp   |   9 +-
 llvm/lib/AsmParser/LLParser.cpp               |   4 +-
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp     |   8 +-
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp     |   2 +-
 llvm/lib/LTO/CMakeLists.txt                   |   1 -
 llvm/lib/LTO/LTO.cpp                          |   3 -
 llvm/lib/LTO/SummaryBasedOptimizations.cpp    |  88 -----------
 llvm/lib/LTO/ThinLTOCodeGenerator.cpp         |   3 -
 llvm/lib/Passes/PassBuilderPipelines.cpp      |   9 --
 llvm/lib/Passes/PassRegistry.def              |   1 -
 llvm/lib/Transforms/IPO/CMakeLists.txt        |   1 -
 .../IPO/SyntheticCountsPropagation.cpp        | 139 ------------------
 .../Transforms/Utils/FunctionImportUtils.cpp  |  18 +--
 .../SyntheticCountsPropagation/initial.ll     |  79 ----------
 .../SyntheticCountsPropagation/prop.ll        |  50 -------
 .../SyntheticCountsPropagation/scc.ll         |  19 ---
 llvm/utils/gn/secondary/llvm/lib/LTO/BUILD.gn |   1 -
 .../llvm/lib/Transforms/IPO/BUILD.gn          |   1 -
 23 files changed, 17 insertions(+), 487 deletions(-)
 delete mode 100644 llvm/include/llvm/LTO/SummaryBasedOptimizations.h
 delete mode 100644 llvm/include/llvm/Transforms/IPO/SyntheticCountsPropagation.h
 delete mode 100644 llvm/lib/LTO/SummaryBasedOptimizations.cpp
 delete mode 100644 llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp
 delete mode 100644 llvm/test/Transforms/SyntheticCountsPropagation/initial.ll
 delete mode 100644 llvm/test/Transforms/SyntheticCountsPropagation/prop.ll
 delete mode 100644 llvm/test/Transforms/SyntheticCountsPropagation/scc.ll

diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt
index 62871133a68075..28623554d35a11 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 00934cc1ce6f2d..5bcf3e88622a25 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; }
 
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
index b2747d24c5396d..6c6c0da6faf81e 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
@@ -231,7 +231,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 f41907f0351257..a1ed6b6b28d0fd 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -9442,8 +9442,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 d4dbab04e8ecdb..0dfee04a493696 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -7673,8 +7673,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),
@@ -7819,8 +7819,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 33ec14b60dd288..9d3400125e172e 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4714,7 +4714,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
         getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDecl(FS)));
     NameVals.push_back(FS->instCount());
     NameVals.push_back(getEncodedFFlags(FS->fflags()));
-    NameVals.push_back(FS->entryCount());
+    NameVals.push_back(0 /* EntryCount */);
 
     // Fill in below
     NameVals.push_back(0); // numrefs
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 bb3c9f7acdb8e5..4f1a988dbae1d7 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1713,9 +1713,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);
-
   DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists(
       ThinLTO.ModuleMap.size());
   DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(
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 57c94e1988b796..2573c811994647 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -1046,9 +1046,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 6927a2886b962b..610b95c0b9a9c4 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -153,11 +153,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::opt<bool>
     EnablePGOInlineDeferral("enable-npm-pgo-inline-deferral", cl::init(true),
@@ -1212,10 +1207,6 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   if (IsMemprofUse)
     MPM.addPass(MemProfUsePass(PGOOpt->MemoryProfile, PGOOpt->FS));
 
-  // Synthesize function entry counts for non-PGO compilation.
-  if (EnableSyntheticCounts && !PGOOpt)
-    MPM.addPass(SyntheticCountsPropagation());
-
   if (EnablePGOForceFunctionAttrs && PGOOpt)
     MPM.addPass(PGOForceFunctionAttrsPass(PGOOpt->ColdOptType));
 
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 95842d15a35bf6..772a4e8a022eb2 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -139,7 +139,6 @@ MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass())
 MODULE_PASS("strip-debug-declare", StripDebugDeclarePass())
 MODULE_PASS("strip-nondebug", StripNonDebugSymbolsPass())
 MODULE_PASS("strip-nonlinetable-debuginfo", StripNonLineTableDebugInfoPass())
-MODULE_PASS("synthetic-counts-propagation", SyntheticCountsPropagation())
 MODULE_PASS("trigger-crash-module", TriggerCrashModulePass())
 MODULE_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
 MODULE_PASS("tsan-module", ModuleThreadSanitizerPass())
diff --git a/llvm/lib/Transforms/IPO/CMakeLists.txt b/llvm/lib/Transforms/IPO/CMakeLists.txt
index 92a9697720efd4..15cb57399d2460 100644
--- a/llvm/lib/Transforms/IPO/CMakeLists.txt
+++ b/llvm/lib/Transforms/IPO/CMakeLists.txt
@@ -41,7 +41,6 @@ add_llvm_component_library(LLVMipo
   SCCP.cpp
   StripDeadPrototypes.cpp
   StripSymbols.cpp
-  SyntheticCountsPropagation.cpp
   ThinLTOBitcodeWriter.cpp
   WholeProgramDevirt.cpp
 
diff --git a/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp b/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp
deleted file mode 100644
index f6f8956760848a..00000000000000
--- a/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-//=- SyntheticCountsPropagation.cpp - 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements a transformation that synthesizes entry counts for
-// functions and attaches !prof metadata to functions with the synthesized
-// counts. The presence of !prof metadata with counter name set to
-// 'synthesized_function_entry_count' indicate that the value of the counter is
-// an estimation of the likely execution count of the function. This transform
-// is applied only in non PGO mode as functions get 'real' profile-based
-// function entry counts in the PGO mode.
-//
-// The transformation works by first assigning some initial values to the entry
-// counts of all functions and then doing a top-down traversal of the
-// callgraph-scc to propagate the counts. For each function the set of callsites
-// and their relative block frequency is gathered. The relative block frequency
-// multiplied by the entry count of the caller and added to the callee's entry
-// count. For non-trivial SCCs, the new counts are computed from the previous
-// counts and updated in one shot.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Transforms/IPO/SyntheticCountsPropagation.h"
-#include "llvm/Analysis/BlockFrequencyInfo.h"
-#include "llvm/Analysis/CallGraph.h"
-#include "llvm/Analysis/SyntheticCountsUtils.h"
-#include "llvm/IR/Function.h"
-#include "llvm/IR/Instructions.h"
-#include "llvm/IR/Module.h"
-#include "llvm/Support/CommandLine.h"
-
-using namespace llvm;
-using Scaled64 = ScaledNumber<uint64_t>;
-using ProfileCount = Function::ProfileCount;
-
-#define DEBUG_TYPE "synthetic-counts-propagation"
-
-namespace llvm {
-cl::opt<int>
-    InitialSyntheticCount("initial-synthetic-count", cl::Hidden, cl::init(10),
-                          cl::desc("Initial value of synthetic entry count"));
-} // namespace llvm
-
-/// Initial synthetic count assigned to inline functions.
-static cl::opt<int> InlineSyntheticCount(
-    "inline-synthetic-count", cl::Hidden, cl::init(15),
-    cl::desc("Initial synthetic entry count for inline functions."));
-
-/// Initial synthetic count assigned to cold functions.
-static cl::opt<int> ColdSyntheticCount(
-    "cold-synthetic-count", cl::Hidden, cl::init(5),
-    cl::desc("Initial synthetic entry count for cold functions."));
-
-// Assign initial synthetic entry counts to functions.
-static void
-initializeCounts(Module &M, function_ref<void(Function *, uint64_t)> SetCount) {
-  auto MayHaveIndirectCalls = [](Function &F) {
-    for (auto *U : F.users()) {
-      if (!isa<CallInst>(U) && !isa<InvokeInst>(U))
-        return true;
-    }
-    return false;
-  };
-
-  for (Function &F : M) {
-    uint64_t InitialCount = InitialSyntheticCount;
-    if (F.isDeclaration())
-      continue;
-    if (F.hasFnAttribute(Attribute::AlwaysInline) ||
-        F.hasFnAttribute(Attribute::InlineHint)) {
-      // Use a higher value for inline functions to account for the fact that
-      // these are usually beneficial to inline.
-      InitialCount = InlineSyntheticCount;
-    } else if (F.hasLocalLinkage() && !MayHaveIndirectCalls(F)) {
-      // Local functions without inline hints get counts only through
-      // propagation.
-      InitialCount = 0;
-    } else if (F.hasFnAttribute(Attribute::Cold) ||
-               F.hasFnAttribute(Attribute::NoInline)) {
-      // Use a lower value for noinline and cold functions.
-      InitialCount = ColdSyntheticCount;
-    }
-    SetCount(&F, InitialCount);
-  }
-}
-
-PreservedAnalyses SyntheticCountsPropagation::run(Module &M,
-                                                  ModuleAnalysisManager &MAM) {
-  FunctionAnalysisManager &FAM =
-      MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
-  DenseMap<Function *, Scaled64> Counts;
-  // Set initial entry counts.
-  initializeCounts(
-      M, [&](Function *F, uint64_t Count) { Counts[F] = Scaled64(Count, 0); });
-
-  // Edge includes information about the source. Hence ignore the first
-  // parameter.
-  auto GetCallSiteProfCount = [&](const CallGraphNode *,
-                                  const CallGraphNode::CallRecord &Edge) {
-    std::optional<Scaled64> Res;
-    if (!Edge.first)
-      return Res;
-    CallBase &CB = *cast<CallBase>(*Edge.first);
-    Function *Caller = CB.getCaller();
-    auto &BFI = FAM.getResult<BlockFrequencyAnalysis>(*Caller);
-
-    // Now compute the callsite count from relative frequency and
-    // entry count:
-    BasicBlock *CSBB = CB.getParent();
-    Scaled64 EntryFreq(BFI.getEntryFreq().getFrequency(), 0);
-    Scaled64 BBCount(BFI.getBlockFreq(CSBB).getFrequency(), 0);
-    BBCount /= EntryFreq;
-    BBCount *= Counts[Caller];
-    return std::optional<Scaled64>(BBCount);
-  };
-
-  CallGraph CG(M);
-  // Propgate the entry counts on the callgraph.
-  SyntheticCountsUtils<const CallGraph *>::propagate(
-      &CG, GetCallSiteProfCount, [&](const CallGraphNode *N, Scaled64 New) {
-        auto F = N->getFunction();
-        if (!F || F->isDeclaration())
-          return;
-
-        Counts[F] += New;
-      });
-
-  // Set the counts as metadata.
-  for (auto Entry : Counts) {
-    Entry.first->setEntryCount(ProfileCount(
-        Entry.second.template toInt<uint64_t>(), Function::PCT_Synthetic));
-  }
-
-  return PreservedAnalyses::all();
-}
diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
index 87be6be018857c..766c7501550da5 100644
--- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -220,24 +220,8 @@ FunctionImportGlobalProcessing::getLinkage(const GlobalValue *SGV,
 void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
 
   ValueInfo VI;
-  if (GV.hasName()) {
+  if (GV.hasName())
     VI = ImportIndex.getValueInfo(GV.getGUID());
-    // Set synthetic function entry counts.
-    if (VI && ImportIndex.hasSyntheticEntryCounts()) {
-      if (Function *F = dyn_cast<Function>(&GV)) {
-        if (!F->isDeclaration()) {
-          for (const auto &S : VI.getSummaryList()) {
-            auto *FS = cast<FunctionSummary>(S->getBaseObject());
-            if (FS->modulePath() == M.getModuleIdentifier()) {
-              F->setEntryCount(Function::ProfileCount(FS->entryCount(),
-                                                      Function::PCT_Synthetic));
-              break;
-            }
-          }
-        }
-      }
-    }
-  }
 
   // We should always have a ValueInfo (i.e. GV in index) for definitions when
   // we are exporting, and also when importing that value.
diff --git a/llvm/test/Transforms/SyntheticCountsPropagation/initial.ll b/llvm/test/Transforms/SyntheticCountsPropagation/initial.ll
deleted file mode 100644
index 40f7111247e4a1..00000000000000
--- a/llvm/test/Transforms/SyntheticCountsPropagation/initial.ll
+++ /dev/null
@@ -1,79 +0,0 @@
-; RUN: opt -passes=synthetic-counts-propagation -S < %s | FileCheck %s
-
-; CHECK-LABEL: define void @foo()
-; CHECK: !prof ![[COUNT1:[0-9]+]]
-define void @foo() {
-  ret void
-}
-
-; CHECK-LABEL: define void @foo_inline() #0
-; CHECK: !prof ![[COUNT2:[0-9]+]]
-define void @foo_inline() #0 {
-  ret void
-}
-
-; CHECK-LABEL: define void @foo_always_inline() #1
-; CHECK: !prof ![[COUNT2]]
-define void @foo_always_inline() #1 {
-  ret void
-}
-
-; CHECK-LABEL: define void @foo_cold() #2
-; CHECK: !prof ![[COUNT3:[0-9]+]]
-define void @foo_cold() #2 {
-  ret void
-}
-
-; CHECK-LABEL: define void @foo_noinline() #3
-; CHECK: !prof ![[COUNT3]]
-define void @foo_noinline() #3 {
-  ret void
-}
-
-; CHECK-LABEL: define internal void @foo_local()
-; CHECK: !prof ![[COUNT4:[0-9]+]]
-define internal void @foo_local() {
-  ret void
-}
-
-; CHECK-LABEL: define internal void @foo_local_escaped()
-; CHECK: !prof ![[COUNT1]]
-define internal void @foo_local_escaped() {
-  ret void
-}
-
-declare void @ext(ptr)
-
-define void @bar() {
-  call void @ext(ptr nonnull @foo_local_escaped)
-  ret void
-}
-
-; CHECK-LABEL: define internal void @foo_local_inline() #0
-; CHECK: !prof ![[COUNT2]]
-define internal void @foo_local_inline() #0 {
-  ret void
-}
-
-; CHECK-LABEL: define internal void @foo_local_cold() #2
-; CHECK: !prof ![[COUNT4]]
-define internal void @foo_local_cold() #2 {
-  ret void
-}
-
-; CHECK-LABEL: define linkonce void @foo_linkonce()
-; CHECK: !prof ![[COUNT1]]
-define linkonce void @foo_linkonce() {
-  ret void
-}
-
-; CHECK: ![[COUNT1]] = !{!"synthetic_function_entry_count", i64 10}
-; CHECK: ![[COUNT2]] = !{!"synthetic_function_entry_count", i64 15}
-; CHECK: ![[COUNT3]] = !{!"synthetic_function_entry_count", i64 5}
-; CHECK: ![[COUNT4]] = !{!"synthetic_function_entry_count", i64 0}
-
-attributes #0 = {inlinehint}
-attributes #1 = {alwaysinline}
-attributes #2 = {cold}
-attributes #3 = {noinline}
-
diff --git a/llvm/test/Transforms/SyntheticCountsPropagation/prop.ll b/llvm/test/Transforms/SyntheticCountsPropagation/prop.ll
deleted file mode 100644
index 68fb8f523ed0d6..00000000000000
--- a/llvm/test/Transforms/SyntheticCountsPropagation/prop.ll
+++ /dev/null
@@ -1,50 +0,0 @@
-; RUN: opt -passes=synthetic-counts-propagation -S < %s | FileCheck %s
-
-; CHECK-LABEL: define void @level1a(i32 %n)
-; CHECK: !prof ![[COUNT1:[0-9]+]]
-define void @level1a(i32 %n) {
-entry:
-  %cmp = icmp sgt i32 %n, 10
-  br i1 %cmp, label %exit, label %loop
-loop:
-  %i = phi i32 [%n, %entry], [%i1, %loop]
-  call void @level2a(i32 %n)
-  %i1 = sub i32 %i, 1
-  %cmp2 = icmp eq i32 %i1, 0
-  br i1 %cmp2, label %exit, label %loop, !prof !1
-exit:
-  ret void
-}
-
-; CHECK-LABEL: define void @level2a(i32 %n)
-; CHECK: !prof ![[COUNT2:[0-9]+]]
-define void @level2a(i32 %n) {
-  call void @level2b(i32 %n)
-  ret void
-}
-
-; CHECK-LABEL: define void @level2b(i32 %n)
-; CHECK: !prof ![[COUNT2]]
-define void @level2b(i32 %n) {
-entry:
-  call void @level2a(i32 %n)
-  %cmp = icmp eq i32 %n, 0
-  br i1 %cmp, label %then, label %else, !prof !2
-then:
-  call void @level3a(i32 %n)
-  br label %else
-else:
-  ret void
-}
-
-; CHECK-LABEL: define internal void @level3a(i32 %n)
-; CHECK: !prof ![[COUNT3:[0-9]+]]
-define internal void @level3a(i32 %n) {
-  ret void
-}
-
-!1 = !{!"branch_weights", i32 1, i32 99}
-!2 = !{!"branch_weights", i32 1, i32 1}
-; CHECK: ![[COUNT1]] = !{!"synthetic_function_entry_count", i64 10}
-; CHECK: ![[COUNT2]] = !{!"synthetic_function_entry_count", i64 520}
-; CHECK: ![[COUNT3]] = !{!"synthetic_function_entry_count", i64 260}
diff --git a/llvm/test/Transforms/SyntheticCountsPropagation/scc.ll b/llvm/test/Transforms/SyntheticCountsPropagation/scc.ll
deleted file mode 100644
index e2d9ada7fb451a..00000000000000
--- a/llvm/test/Transforms/SyntheticCountsPropagation/scc.ll
+++ /dev/null
@@ -1,19 +0,0 @@
-; RUN: opt -passes=synthetic-counts-propagation -S < %s | FileCheck %s
-
-; CHECK-LABEL: define void @foo()
-; CHECK: !prof ![[COUNT1:[0-9]+]]
-define void @foo() {
-  call void @bar()
-  ret void
-}
-
-; CHECK-LABEL: define void @bar() #0
-; CHECK: !prof ![[COUNT1]]
-define void @bar() #0 {
-  call void @foo()
-  ret void
-}
-
-attributes #0 = {inlinehint}
-
-; CHECK: ![[COUNT1]] = !{!"synthetic_function_entry_count", i64 25}
diff --git a/llvm/utils/gn/secondary/llvm/lib/LTO/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/LTO/BUILD.gn
index 6c44a25b2acbea..001ca38177fe1d 100644
--- a/llvm/utils/gn/secondary/llvm/lib/LTO/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/LTO/BUILD.gn
@@ -27,7 +27,6 @@ static_library("LTO") {
     "LTOBackend.cpp",
     "LTOCodeGenerator.cpp",
     "LTOModule.cpp",
-    "SummaryBasedOptimizations.cpp",
     "ThinLTOCodeGenerator.cpp",
     "UpdateCompilerUsed.cpp",
   ]
diff --git a/llvm/utils/gn/secondary/llvm/lib/Transforms/IPO/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Transforms/IPO/BUILD.gn
index bcf2ea7510568d..9c7798116356fb 100644
--- a/llvm/utils/gn/secondary/llvm/lib/Transforms/IPO/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/Transforms/IPO/BUILD.gn
@@ -62,7 +62,6 @@ static_library("IPO") {
     "SampleProfileProbe.cpp",
     "StripDeadPrototypes.cpp",
     "StripSymbols.cpp",
-    "SyntheticCountsPropagation.cpp",
     "ThinLTOBitcodeWriter.cpp",
     "WholeProgramDevirt.cpp",
   ]

>From f2524f5111229627dea4ed6c43ae142ab11167ee Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Thu, 5 Sep 2024 14:47:23 -0700
Subject: [PATCH 2/4] clean up index flag bit

---
 llvm/include/llvm/IR/ModuleSummaryIndex.h     |  3 --
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp     |  1 +
 llvm/lib/IR/ModuleSummaryIndex.cpp            |  8 +---
 .../Bitcode/thinlto-synthetic-count-flag.ll   | 21 ---------
 llvm/test/ThinLTO/X86/function_entry_count.ll | 45 -------------------
 5 files changed, 3 insertions(+), 75 deletions(-)
 delete mode 100644 llvm/test/Bitcode/thinlto-synthetic-count-flag.ll
 delete mode 100644 llvm/test/ThinLTO/X86/function_entry_count.ll

diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 5bcf3e88622a25..9844d5abf39525 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1567,9 +1567,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/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 9d3400125e172e..c8421d35f6dca5 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4714,6 +4714,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
         getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDecl(FS)));
     NameVals.push_back(FS->instCount());
     NameVals.push_back(getEncodedFFlags(FS->fflags()));
+    // TODO: Stop writing entry count and bump bitcode version.
     NameVals.push_back(0 /* EntryCount */);
 
     // Fill in below
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/test/Bitcode/thinlto-synthetic-count-flag.ll b/llvm/test/Bitcode/thinlto-synthetic-count-flag.ll
deleted file mode 100644
index 1b92a15145ca43..00000000000000
--- a/llvm/test/Bitcode/thinlto-synthetic-count-flag.ll
+++ /dev/null
@@ -1,21 +0,0 @@
-; REQUIRES: x86-registered-target
-; RUN: opt -module-summary %s -o %t.o
-
-; Ensure synthetic entry count flag is not set on distributed index
-; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
-; RUN:		-r %t.o,glob,plx -compute-dead=false
-; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=NOSYNTHETIC
-; NOSYNTHETIC: <FLAGS op0=96/>
-
-; Ensure synthetic entry count flag is set on distributed index
-; when option used to enable synthetic count propagation
-; RUN: llvm-lto2 run %t.o -o %t.out -thinlto-distributed-indexes \
-; RUN:		-r %t.o,glob,plx -thinlto-synthesize-entry-counts \
-; RUN:          -compute-dead=false
-; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=HASSYNTHETIC
-; HASSYNTHETIC: <FLAGS op0=100/>
-
-target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
-
- at glob = global i32 0
diff --git a/llvm/test/ThinLTO/X86/function_entry_count.ll b/llvm/test/ThinLTO/X86/function_entry_count.ll
deleted file mode 100644
index b65bc226040bfc..00000000000000
--- a/llvm/test/ThinLTO/X86/function_entry_count.ll
+++ /dev/null
@@ -1,45 +0,0 @@
-; RUN: opt -thinlto-bc %s -write-relbf-to-summary -thin-link-bitcode-file=%t1.thinlink.bc -o %t1.bc
-; RUN: opt -thinlto-bc %p/Inputs/function_entry_count.ll -write-relbf-to-summary -thin-link-bitcode-file=%t2.thinlink.bc -o %t2.bc
-
-; First perform the thin link on the normal bitcode file.
-; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps -disable-thinlto-funcattrs=0 -thinlto-synthesize-entry-counts \
-; RUN:     -r=%t1.bc,g, \
-; RUN:     -r=%t1.bc,f,px \
-; RUN:     -r=%t1.bc,h,px \
-; RUN:     -r=%t2.bc,h, \
-; RUN:     -r=%t2.bc,g,px
-; RUN: llvm-dis -o - %t.o.1.3.import.bc | FileCheck %s
-
-; RUN: llvm-lto -thinlto-action=run -disable-thinlto-funcattrs=0 -thinlto-synthesize-entry-counts -exported-symbol=f \
-; RUN:     -exported-symbol=g -exported-symbol=h -thinlto-save-temps=%t3. %t1.bc %t2.bc
-; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s
-
-; CHECK: define void @h() [[ATTR:#[0-9]+]] !prof ![[PROF2:[0-9]+]]
-; CHECK: define void @f(i32{{.*}}) [[ATTR:#[0-9]+]] !prof ![[PROF1:[0-9]+]]
-; CHECK: define available_externally void @g() !prof ![[PROF2]]
-; CHECK-DAG: ![[PROF1]] = !{!"synthetic_function_entry_count", i64 10}
-; CHECK-DAG: ![[PROF2]] = !{!"synthetic_function_entry_count", i64 200}
-; CHECK-DAG: attributes [[ATTR]] = { norecurse nounwind }
-
-target triple = "x86_64-unknown-linux-gnu"
-target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-
-declare void @g();
-
-define void @h() {
-  ret void
-}
-
-define void @f(i32 %n) {
-entry:
-  %cmp = icmp slt i32 %n, 1
-  br i1 %cmp, label %exit, label %loop
-loop:
-  %n1 = phi i32 [%n, %entry], [%n2, %loop]
-  call void  @g()
-  %n2 = sub i32 %n1, 1
-  %cmp2 = icmp slt i32 %n, 1
-  br i1 %cmp2, label %exit, label %loop
-exit:
-  ret void
-}

>From 157c9a86efdea3382bfa9c1a7fa1d7b5c46c48ef Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Thu, 5 Sep 2024 15:52:01 -0700
Subject: [PATCH 3/4] clean up headers

---
 llvm/lib/LTO/LTO.cpp                  | 1 -
 llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 1 -
 2 files changed, 2 deletions(-)

diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 52641720a5e6d0..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"
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 63577e26530ac4..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"

>From 7bd981bbaf8cc35e865b296fc2ca59eb2a62d671 Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Thu, 5 Sep 2024 16:06:12 -0700
Subject: [PATCH 4/4] one clean up and one clang-format

---
 llvm/lib/LTO/ThinLTOCodeGenerator.cpp    | 2 +-
 llvm/lib/Passes/PassBuilderPipelines.cpp | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 7454b30bea2cb6..76268c950cf581 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -27,9 +27,9 @@
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
-#include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/LLVMRemarkStreamer.h"
+#include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Mangler.h"
 #include "llvm/IR/PassTimingInfo.h"
 #include "llvm/IR/Verifier.h"
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index f344afc9b87922..2194be155c12d8 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -68,7 +68,6 @@
 #include "llvm/Transforms/IPO/SCCP.h"
 #include "llvm/Transforms/IPO/SampleProfile.h"
 #include "llvm/Transforms/IPO/SampleProfileProbe.h"
-#include "llvm/Transforms/IPO/SyntheticCountsPropagation.h"
 #include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/InstCombine/InstCombine.h"
 #include "llvm/Transforms/Instrumentation/CGProfile.h"



More information about the cfe-commits mailing list