Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CGData][MachineOutliner] Global Outlining #90074

Merged
merged 3 commits into from
Sep 10, 2024

Conversation

kyulee-com
Copy link
Contributor

@kyulee-com kyulee-com commented Apr 25, 2024

This commit introduces support for outlining functions across modules using codegen data generated from previous codegen. The codegen data currently manages the outlined hash tree, which records outlining instances that occurred locally in the past.

The machine outliner now operates in one of three modes:

  1. CGDataMode::None: This is the default outliner mode that uses the suffix tree to identify (local) outlining candidates within a module. This mode is also used by (full)LTO to maintain optimal behavior with the combined module.
  2. CGDataMode::Write (-codegen-data-generate): This mode is identical to the default mode, but it also publishes the stable hash sequences of instructions in the outlined functions into a local outlined hash tree. It then encodes this into the __llvm_outline section, which will be dead-stripped at link time.
  3. CGDataMode::Read (-codegen-data-use-path={.cgdata}): This mode reads a codegen data file (.cgdata) and initializes a global outlined hash tree. This tree is used to generate global outlining candidates. Note that the codegen data file has been post-processed with the raw __llvm_outline sections from all native objects using the llvm-cgdata tool (or a linker, LLD, or a new ThinLTO pipeline later).

This depends on #105398. After this PR, LLD (#90166) and Clang (#90304) will follow for each client side support.
This is a patch for https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.

@kyulee-com kyulee-com force-pushed the globaloutline branch 2 times, most recently from 35b9da2 to 80df5a2 Compare April 26, 2024 16:41
@kyulee-com kyulee-com changed the title [MachineOutliner][CGData] Global Outlining [CGData][MachineOutliner] Global Outlining May 3, 2024
kyulee-com added a commit that referenced this pull request Aug 27, 2024
This patch prepares the NFC groundwork for global outlining using
CGData, which will follow
#90074.

- The `MinRepeats` parameter is now explicitly passed to the
`getOutliningCandidateInfo` function, rather than relying on a default
value of 2. For local outlining, the minimum number of repetitions is
typically 2, but for the global outlining (mentioned above), we will
optimistically create a single `Candidate` for each `OutlinedFunction`
if stable hashes match a specific code sequence. This parameter is
adjusted accordingly in global outlining scenarios.
- I have also implemented `unique_ptr` for `OutlinedFunction` to ensure
safe and efficient memory management within `FunctionList`, avoiding
unnecessary implicit copies.

This depends on #101461.
This is a patch for
https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.
This commit introduces support for outlining functions across modules using codegen data generated from previous codegen. The codegen data currently manages the outlined hash tree, which records outlining instances that occurred locally in the past.

The machine outliner now operates in one of three modes:
1. CGDataMode::None: This is the default outliner mode that uses the suffix tree to identify (local) outlining candidates within a module. This mode is also used by (full)LTO to maintain optimal behavior with the combined module.
2. CGDataMode::Write (`codegen-data-generate`): This mode is identical to the default mode, but it also publishes the stable hash sequences of instructions in the outlined functions into a local outlined hash tree. It then encodes this into the `__llvm_outline` section, which will be dead-stripped at link time.
3. CGDataMode::Read (`codegen-data-use-path={.cgdata}`): This mode reads a codegen data file (.cgdata) and initializes a global outlined hash tree. This tree is used to generate global outlining candidates. Note that the codegen data file has been post-processed with the raw `__llvm_outline` sections from all native objects using the `llvm-cgdata` tool (or a linker, `LLD`, or a new ThinLTO pipeline later).
@@ -128,6 +135,19 @@ static cl::opt<bool> OutlinerLeafDescendants(
"tree as candidates for outlining (if false, only leaf children "
"are considered)"));

static cl::opt<bool>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These flags are currently added for testing purposes and are not strictly necessary. However, if everyone agrees, I am happy to remove them.

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 28, 2024

@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-llvm-adt

Author: Kyungwoo Lee (kyulee-com)

Changes

This commit introduces support for outlining functions across modules using codegen data generated from previous codegen. The codegen data currently manages the outlined hash tree, which records outlining instances that occurred locally in the past.

The machine outliner now operates in one of three modes:

  1. CGDataMode::None: This is the default outliner mode that uses the suffix tree to identify (local) outlining candidates within a module. This mode is also used by (full)LTO to maintain optimal behavior with the combined module.
  2. CGDataMode::Write (-codegen-data-generate): This mode is identical to the default mode, but it also publishes the stable hash sequences of instructions in the outlined functions into a local outlined hash tree. It then encodes this into the __llvm_outline section, which will be dead-stripped at link time.
  3. CGDataMode::Read (-codegen-data-use-path={.cgdata}): This mode reads a codegen data file (.cgdata) and initializes a global outlined hash tree. This tree is used to generate global outlining candidates. Note that the codegen data file has been post-processed with the raw __llvm_outline sections from all native objects using the llvm-cgdata tool (or a linker, LLD, or a new ThinLTO pipeline later).

This depends on #105398. After this PR, LLD (#90166) and Clang (#90304) will follow for each client side support.
This is a patch for https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.


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

16 Files Affected:

  • (modified) llvm/include/llvm/ADT/StableHashing.h (+6)
  • (modified) llvm/include/llvm/CodeGen/MachineOutliner.h (+38-2)
  • (modified) llvm/lib/CGData/CodeGenData.cpp (+25-1)
  • (modified) llvm/lib/CodeGen/CMakeLists.txt (+1)
  • (modified) llvm/lib/CodeGen/MachineOutliner.cpp (+260-1)
  • (modified) llvm/test/CodeGen/AArch64/O3-pipeline.ll (+1)
  • (added) llvm/test/CodeGen/AArch64/cgdata-global-hash.ll (+40)
  • (added) llvm/test/CodeGen/AArch64/cgdata-outlined-name.ll (+41)
  • (added) llvm/test/CodeGen/AArch64/cgdata-read-double-outline.ll (+57)
  • (added) llvm/test/CodeGen/AArch64/cgdata-read-lto-outline.ll (+96)
  • (added) llvm/test/CodeGen/AArch64/cgdata-read-priority.ll (+68)
  • (added) llvm/test/CodeGen/AArch64/cgdata-read-single-outline-suffix.ll (+100)
  • (added) llvm/test/CodeGen/AArch64/cgdata-read-single-outline.ll (+42)
  • (added) llvm/test/CodeGen/AArch64/cgdata-write-outline.ll (+51)
  • (modified) llvm/test/CodeGen/RISCV/O3-pipeline.ll (+1)
  • (modified) llvm/unittests/MIR/MachineStableHashTest.cpp (+70)
diff --git a/llvm/include/llvm/ADT/StableHashing.h b/llvm/include/llvm/ADT/StableHashing.h
index 7852199f8b0a00..b220a0ed1f9131 100644
--- a/llvm/include/llvm/ADT/StableHashing.h
+++ b/llvm/include/llvm/ADT/StableHashing.h
@@ -53,6 +53,12 @@ inline stable_hash stable_hash_combine(stable_hash A, stable_hash B,
 // Removes suffixes introduced by LLVM from the name to enhance stability and
 // maintain closeness to the original name across different builds.
 inline StringRef get_stable_name(StringRef Name) {
+  // Return the part after ".content." that represents contents.
+  auto [P0, S0] = Name.rsplit(".content.");
+  if (!S0.empty())
+    return S0;
+
+  // Ignore these suffixes.
   auto [P1, S1] = Name.rsplit(".llvm.");
   auto [P2, S2] = P1.rsplit(".__uniq.");
   return P2;
diff --git a/llvm/include/llvm/CodeGen/MachineOutliner.h b/llvm/include/llvm/CodeGen/MachineOutliner.h
index eaba6c9b18f2bb..fbb958ccf6488e 100644
--- a/llvm/include/llvm/CodeGen/MachineOutliner.h
+++ b/llvm/include/llvm/CodeGen/MachineOutliner.h
@@ -18,6 +18,7 @@
 #include "llvm/CodeGen/LiveRegUnits.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/MachineStableHash.h"
 #include <initializer_list>
 
 namespace llvm {
@@ -234,11 +235,11 @@ struct OutlinedFunction {
   unsigned FrameConstructionID = 0;
 
   /// Return the number of candidates for this \p OutlinedFunction.
-  unsigned getOccurrenceCount() const { return Candidates.size(); }
+  virtual unsigned getOccurrenceCount() const { return Candidates.size(); }
 
   /// Return the number of bytes it would take to outline this
   /// function.
-  unsigned getOutliningCost() const {
+  virtual unsigned getOutliningCost() const {
     unsigned CallOverhead = 0;
     for (const Candidate &C : Candidates)
       CallOverhead += C.getCallOverhead();
@@ -272,7 +273,42 @@ struct OutlinedFunction {
   }
 
   OutlinedFunction() = delete;
+  virtual ~OutlinedFunction() = default;
 };
+
+/// The information necessary to create an outlined function that is matched
+/// globally.
+struct GlobalOutlinedFunction : public OutlinedFunction {
+  explicit GlobalOutlinedFunction(std::unique_ptr<OutlinedFunction> OF,
+                                  unsigned GlobalOccurrenceCount)
+      : OutlinedFunction(*OF), GlobalOccurrenceCount(GlobalOccurrenceCount) {}
+
+  unsigned GlobalOccurrenceCount;
+
+  /// Return the number of times that appear globally.
+  /// Global outlining candidate is uniquely created per each match, but this
+  /// might be erased out when it's overlapped with the previous outlining
+  /// instance.
+  unsigned getOccurrenceCount() const override {
+    assert(Candidates.size() <= 1);
+    return Candidates.empty() ? 0 : GlobalOccurrenceCount;
+  }
+
+  /// Return the outlining cost using the global occurrence count
+  /// with the same cost as the first (unique) candidate.
+  unsigned getOutliningCost() const override {
+    assert(Candidates.size() <= 1);
+    unsigned CallOverhead =
+        Candidates.empty()
+            ? 0
+            : Candidates[0].getCallOverhead() * getOccurrenceCount();
+    return CallOverhead + SequenceSize + FrameOverhead;
+  }
+
+  GlobalOutlinedFunction() = delete;
+  ~GlobalOutlinedFunction() = default;
+};
+
 } // namespace outliner
 } // namespace llvm
 
diff --git a/llvm/lib/CGData/CodeGenData.cpp b/llvm/lib/CGData/CodeGenData.cpp
index 9dd4b1674e094a..55d2504231c744 100644
--- a/llvm/lib/CGData/CodeGenData.cpp
+++ b/llvm/lib/CGData/CodeGenData.cpp
@@ -24,6 +24,13 @@
 using namespace llvm;
 using namespace cgdata;
 
+cl::opt<bool>
+    CodeGenDataGenerate("codegen-data-generate", cl::init(false), cl::Hidden,
+                        cl::desc("Emit CodeGen Data into custom sections"));
+cl::opt<std::string>
+    CodeGenDataUsePath("codegen-data-use-path", cl::init(""), cl::Hidden,
+                       cl::desc("File path to where .cgdata file is read"));
+
 static std::string getCGDataErrString(cgdata_error Err,
                                       const std::string &ErrMsg = "") {
   std::string Msg;
@@ -132,7 +139,24 @@ CodeGenData &CodeGenData::getInstance() {
   std::call_once(CodeGenData::OnceFlag, []() {
     Instance = std::unique_ptr<CodeGenData>(new CodeGenData());
 
-    // TODO: Initialize writer or reader mode for the client optimization.
+    if (CodeGenDataGenerate)
+      Instance->EmitCGData = true;
+    else if (!CodeGenDataUsePath.empty()) {
+      // Initialize the global CGData if the input file name is given.
+      // We do not error-out when failing to parse the input file.
+      // Instead, just emit an warning message and fall back as if no CGData
+      // were available.
+      auto FS = vfs::getRealFileSystem();
+      auto ReaderOrErr = CodeGenDataReader::create(CodeGenDataUsePath, *FS);
+      if (Error E = ReaderOrErr.takeError()) {
+        warn(std::move(E), CodeGenDataUsePath);
+        return;
+      }
+      // Publish each CGData based on the data type in the header.
+      auto Reader = ReaderOrErr->get();
+      if (Reader->hasOutlinedHashTree())
+        Instance->publishOutlinedHashTree(Reader->releaseOutlinedHashTree());
+    }
   });
   return *(Instance.get());
 }
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index f1607f85c5b319..3e75737185c3ee 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -267,6 +267,7 @@ add_llvm_component_library(LLVMCodeGen
   Analysis
   BitReader
   BitWriter
+  CGData
   CodeGenTypes
   Core
   MC
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index 42f410c277179b..7736df2def77bc 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -59,7 +59,9 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/Analysis/ModuleSummaryAnalysis.h"
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
+#include "llvm/CGData/CodeGenDataReader.h"
 #include "llvm/CodeGen/LivePhysRegs.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
@@ -75,6 +77,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SuffixTree.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
 #include <functional>
 #include <tuple>
 #include <vector>
@@ -98,6 +101,10 @@ STATISTIC(NumInvisible,
           "Invisible instructions skipped during mapping");
 STATISTIC(UnsignedVecSize,
           "Total number of instructions mapped and saved to mapping vector");
+STATISTIC(StableHashAttempts,
+          "Count of hashing attempts made for outlined functions");
+STATISTIC(StableHashDropped,
+          "Count of unsuccessful hashing attempts for outlined functions");
 
 // Set to true if the user wants the outliner to run on linkonceodr linkage
 // functions. This is false by default because the linker can dedupe linkonceodr
@@ -128,6 +135,19 @@ static cl::opt<bool> OutlinerLeafDescendants(
              "tree as candidates for outlining (if false, only leaf children "
              "are considered)"));
 
+static cl::opt<bool>
+    DisableGlobalOutlining("disable-global-outlining", cl::Hidden,
+                           cl::desc("Disable global outlining only by ignoring "
+                                    "the codegen data generation or use"),
+                           cl::init(false));
+
+static cl::opt<bool> AppendContentHashToOutlinedName(
+    "append-content-hash-outlined-name", cl::Hidden,
+    cl::desc("This appends the content hash to the globally outlined function "
+             "name. It's beneficial for enhancing the precision of the stable "
+             "hash and for ordering the outlined functions."),
+    cl::init(true));
+
 namespace {
 
 /// Maps \p MachineInstrs to unsigned integers and stores the mappings.
@@ -421,11 +441,29 @@ struct MachineOutliner : public ModulePass {
   /// Set when the pass is constructed in TargetPassConfig.
   bool RunOnAllFunctions = true;
 
+  /// This is a compact representation of hash sequences of outlined functions.
+  /// It is used when OutlinerMode = CGDataMode::Write.
+  /// The resulting hash tree will be emitted into __llvm_outlined section
+  /// which will be dead-stripped not going to the final binary.
+  /// A post-process using llvm-cgdata, lld, or ThinLTO can merge them into
+  /// a global oulined hash tree for the subsequent codegen.
+  std::unique_ptr<OutlinedHashTree> LocalHashTree;
+
+  /// The mode of the outliner.
+  /// When is's CGDataMode::None, candidates are populated with the suffix tree
+  /// within a module and outlined.
+  /// When it's CGDataMode::Write, in addition to CGDataMode::None, the hash
+  /// sequences of outlined functions are published into LocalHashTree.
+  /// When it's CGDataMode::Read, candidates are populated with the global
+  /// outlined hash tree that has been built by the previous codegen.
+  CGDataMode OutlinerMode = CGDataMode::None;
+
   StringRef getPassName() const override { return "Machine Outliner"; }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<MachineModuleInfoWrapperPass>();
     AU.addPreserved<MachineModuleInfoWrapperPass>();
+    AU.addRequired<ImmutableModuleSummaryIndexWrapperPass>();
     AU.setPreservesAll();
     ModulePass::getAnalysisUsage(AU);
   }
@@ -460,6 +498,16 @@ struct MachineOutliner : public ModulePass {
   findCandidates(InstructionMapper &Mapper,
                  std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList);
 
+  /// Find all repeated substrings that match in the global outlined hash
+  /// tree built from the previous codegen.
+  ///
+  /// \param Mapper Contains outlining mapping information.
+  /// \param[out] FunctionList Filled with a list of \p OutlinedFunctions
+  /// each type of candidate.
+  void findGlobalCandidates(
+      InstructionMapper &Mapper,
+      std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList);
+
   /// Replace the sequences of instructions represented by \p OutlinedFunctions
   /// with calls to functions.
   ///
@@ -476,6 +524,17 @@ struct MachineOutliner : public ModulePass {
                                           InstructionMapper &Mapper,
                                           unsigned Name);
 
+  /// Compute and publish the stable hash sequence of instructions in the
+  /// outlined function, \p MF. The parameter \p CandSize represents the number
+  /// of candidates that have identical instruction sequences to \p MF.
+  void computeAndPublishHashSequence(MachineFunction &MF, unsigned CandSize);
+
+  /// Initialize the outliner mode.
+  void initializeOutlinerMode(const Module &M);
+
+  /// Emit the outlined hash tree into __llvm_outline section.
+  void emitOutlinedHashTree(Module &M);
+
   /// Calls 'doOutline()' 1 + OutlinerReruns times.
   bool runOnModule(Module &M) override;
 
@@ -585,6 +644,111 @@ void MachineOutliner::emitOutlinedFunctionRemark(OutlinedFunction &OF) {
   MORE.emit(R);
 }
 
+struct MatchedEntry {
+  size_t StartIdx;
+  size_t Length;
+  size_t Count;
+};
+
+static const HashNode *followHashNode(stable_hash StableHash,
+                                      const HashNode *Current) {
+  auto I = Current->Successors.find(StableHash);
+  return (I == Current->Successors.end()) ? nullptr : I->second.get();
+}
+
+// Find all matches in the global outlined hash tree.
+// It's quadratic complexity in theory, but it's nearly linear in practice
+// since the length of outlined sequences are small within a block.
+static std::vector<MatchedEntry> getMatchedEntries(InstructionMapper &Mapper) {
+  auto &InstrList = Mapper.InstrList;
+  auto &UnsignedVec = Mapper.UnsignedVec;
+
+  std::vector<MatchedEntry> MatchedEntries;
+  std::vector<stable_hash> Sequence;
+  auto Size = UnsignedVec.size();
+
+  // Get the global outlined hash tree built from the previous run.
+  assert(cgdata::hasOutlinedHashTree());
+  const auto *RootNode = cgdata::getOutlinedHashTree()->getRoot();
+  for (size_t I = 0; I < Size; ++I) {
+    // skip the invalid mapping that represents a large negative value.
+    if (UnsignedVec[I] >= Size)
+      continue;
+    const MachineInstr &MI = *InstrList[I];
+    // skip debug instructions as we did for the outlined function.
+    if (MI.isDebugInstr())
+      continue;
+    // skip the empty hash value.
+    stable_hash StableHashI = stableHashValue(MI);
+    if (!StableHashI)
+      continue;
+    Sequence.clear();
+    Sequence.push_back(StableHashI);
+
+    const HashNode *LastNode = followHashNode(StableHashI, RootNode);
+    if (!LastNode)
+      continue;
+
+    size_t J = I + 1;
+    for (; J < Size; ++J) {
+      // break on the invalid mapping that represents a large negative value.
+      if (UnsignedVec[J] >= Size)
+        break;
+      // ignore debug instructions as we did for the outlined function.
+      const MachineInstr &MJ = *InstrList[J];
+      if (MJ.isDebugInstr())
+        continue;
+      // break on the empty hash value.
+      stable_hash StableHashJ = stableHashValue(MJ);
+      if (!StableHashJ)
+        break;
+      LastNode = followHashNode(StableHashJ, LastNode);
+      if (!LastNode)
+        break;
+
+      // Even with a match ending with a terminal, we continue finding
+      // matches to populate all candidates.
+      Sequence.push_back(StableHashJ);
+      auto Count = LastNode->Terminals;
+      if (Count)
+        MatchedEntries.push_back({I, J - I + 1, *Count});
+    }
+  }
+
+  return MatchedEntries;
+}
+
+void MachineOutliner::findGlobalCandidates(
+    InstructionMapper &Mapper,
+    std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
+  FunctionList.clear();
+  auto &InstrList = Mapper.InstrList;
+  auto &MBBFlagsMap = Mapper.MBBFlagsMap;
+
+  std::vector<Candidate> CandidatesForRepeatedSeq;
+  for (auto &ME : getMatchedEntries(Mapper)) {
+    CandidatesForRepeatedSeq.clear();
+    MachineBasicBlock::iterator StartIt = InstrList[ME.StartIdx];
+    MachineBasicBlock::iterator EndIt = InstrList[ME.StartIdx + ME.Length - 1];
+    MachineBasicBlock *MBB = StartIt->getParent();
+    CandidatesForRepeatedSeq.emplace_back(ME.StartIdx, ME.Length, StartIt,
+                                          EndIt, MBB, FunctionList.size(),
+                                          MBBFlagsMap[MBB]);
+    const TargetInstrInfo *TII =
+        MBB->getParent()->getSubtarget().getInstrInfo();
+    unsigned MinRepeats = 1;
+    std::optional<std::unique_ptr<OutlinedFunction>> OF =
+        TII->getOutliningCandidateInfo(*MMI, CandidatesForRepeatedSeq,
+                                       MinRepeats);
+    if (!OF.has_value() || OF.value()->Candidates.empty())
+      continue;
+    // We create a global candidate each match.
+    assert(OF.value()->Candidates.size() == MinRepeats);
+    FunctionList.emplace_back(std::make_unique<GlobalOutlinedFunction>(
+        std::move(OF.value()), ME.Count));
+  }
+}
+
 void MachineOutliner::findCandidates(
     InstructionMapper &Mapper,
     std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
@@ -695,6 +859,39 @@ void MachineOutliner::findCandidates(
   }
 }
 
+void MachineOutliner::computeAndPublishHashSequence(MachineFunction &MF,
+                                                    unsigned CandSize) {
+  // Compute the hash sequence for the outlined function.
+  SmallVector<stable_hash> OutlinedHashSequence;
+  for (auto &MBB : MF) {
+    for (auto &NewMI : MBB) {
+      stable_hash Hash = stableHashValue(NewMI);
+      if (!Hash) {
+        OutlinedHashSequence.clear();
+        break;
+      }
+      OutlinedHashSequence.push_back(Hash);
+    }
+  }
+
+  // Append a unique name based on the non-empty hash sequence.
+  if (AppendContentHashToOutlinedName && !OutlinedHashSequence.empty()) {
+    auto CombinedHash = stable_hash_combine(OutlinedHashSequence);
+    auto NewName =
+        MF.getName().str() + ".content." + std::to_string(CombinedHash);
+    MF.getFunction().setName(NewName);
+  }
+
+  // Publish the non-empty hash sequence to the local hash tree.
+  if (OutlinerMode == CGDataMode::Write) {
+    StableHashAttempts++;
+    if (!OutlinedHashSequence.empty())
+      LocalHashTree->insert({OutlinedHashSequence, CandSize});
+    else
+      StableHashDropped++;
+  }
+}
+
 MachineFunction *MachineOutliner::createOutlinedFunction(
     Module &M, OutlinedFunction &OF, InstructionMapper &Mapper, unsigned Name) {
 
@@ -770,6 +967,9 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
     }
   }
 
+  if (OutlinerMode != CGDataMode::None)
+    computeAndPublishHashSequence(MF, OF.Candidates.size());
+
   // Set normal properties for a late MachineFunction.
   MF.getProperties().reset(MachineFunctionProperties::Property::IsSSA);
   MF.getProperties().set(MachineFunctionProperties::Property::NoPHIs);
@@ -1134,12 +1334,65 @@ void MachineOutliner::emitInstrCountChangedRemark(
   }
 }
 
+void MachineOutliner::initializeOutlinerMode(const Module &M) {
+  if (DisableGlobalOutlining)
+    return;
+
+  if (auto *IndexWrapperPass =
+          getAnalysisIfAvailable<ImmutableModuleSummaryIndexWrapperPass>()) {
+    auto *TheIndex = IndexWrapperPass->getIndex();
+    // (Full)LTO module does not have functions added to the index.
+    // In this case, we run the outliner without using codegen data as usual.
+    if (TheIndex && !TheIndex->hasExportedFunctions(M))
+      return;
+  }
+
+  // When codegen data write is enabled, we want to write the local outlined
+  // hash tree to the custom section, `__llvm_outline`.
+  // When the outlined hash tree is available from the previous codegen data,
+  // we want to read it to optimistically create global outlining candidates.
+  if (cgdata::emitCGData()) {
+    OutlinerMode = CGDataMode::Write;
+    // Create a local outlined hash tree to be published.
+    LocalHashTree.reset(new OutlinedHashTree());
+    // We don't need to read the outlined hash tree from the previous codegen
+  } else if (cgdata::hasOutlinedHashTree())
+    OutlinerMode = CGDataMode::Read;
+}
+
+void MachineOutliner::emitOutlinedHashTree(Module &M) {
+  assert(LocalHashTree);
+  if (!LocalHashTree->empty()) {
+    LLVM_DEBUG({
+      dbgs() << "Emit outlined hash tree. Size: " << LocalHashTree->size()
+             << "\n";
+    });
+    SmallVector<char> Buf;
+    raw_svector_ostream OS(Buf);
+
+    OutlinedHashTreeRecord HTR(std::move(LocalHashTree));
+    HTR.serialize(OS);
+
+    llvm::StringRef Data(Buf.data(), Buf.size());
+    std::unique_ptr<MemoryBuffer> Buffer =
+        MemoryBuffer::getMemBuffer(Data, "in-memory outlined hash tree", false);
+
+    Triple TT(M.getTargetTriple());
+    embedBufferInModule(
+        M, *Buffer.get(),
+        getCodeGenDataSectionName(CG_outline, TT.getObjectFormat()));
+  }
+}
+
 bool MachineOutliner::runOnModule(Module &M) {
   // Check if there's anything in the module. If it's empty, then there's
   // nothing to outline.
   if (M.empty())
     return false;
 
+  // Initialize the outliner mode.
+  initializeOutlinerMode(M);
+
   MMI = &getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
 
   // Number to append to the current outlined function.
@@ -1161,6 +1414,9 @@ bool MachineOutliner::runOnModule(Module &M) {
     }
   }
 
+  if (OutlinerMode == CGDataMode::Write)
+    emitOutlinedHashTree(M);
+
   return true;
 }
 
@@ -1189,7 +1445,10 @@ bool MachineOutliner::doOutline(Module &M, unsigned &OutlinedFunctionNum) {
   std::vector<std::unique_ptr<OutlinedFunction>> FunctionList;
 
   // Find all of the outlining candidates.
-  findCandidates(Mapper, FunctionList);
+  if (OutlinerMode == CGDataMode::Read)
+    findGlobalCandidates(Mapper, FunctionList);
+  else
+    findCandidates(Mapper, FunctionList);
 
   // If we've requested size remarks, then collect the MI counts of every
   // function before outlining, and the MI counts after outlining.
diff --git a/llvm/test/CodeGen/AArch64/O3-pipeline.ll b/llvm/test/CodeGen/AArch64/O3-pipeline.ll
index 3465b717261cf5..66ce960462c63d 100644
--- a/llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ b/llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -16,6 +16,7 @@
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT: Default Regalloc Eviction Advisor
 ; CHECK-NEXT: Default Regalloc Priority Advisor
+; CHECK-NEXT: Module summary info
 ; CHECK-NEXT:   M...
[truncated]

assert(cgdata::hasOutlinedHashTree());
const auto *RootNode = cgdata::getOutlinedHashTree()->getRoot();
for (size_t I = 0; I < Size; ++I) {
// skip the invalid mapping that represents a large negative value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize the first letter in comments (also the others in this function)

but also, what's this large negative value meaning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch! The large negative value (starting from -3) in the InstructionMapper indicates that an instruction mapping is not valid or legal -- https://github.com/kyulee-com/llvm-project/blob/master/llvm/lib/CodeGen/MachineOutliner.cpp#L216-L217, which I implicitly relied on. Instead, to clarify the code, I now check a valid mapping with Mapper.LegalInstrNumber.

if (OutlinerMode == CGDataMode::Write) {
StableHashAttempts++;
if (!OutlinedHashSequence.empty())
LocalHashTree->insert({OutlinedHashSequence, CandSize});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to store the number of candidates for this already-outlined function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We track the frequency of each outlined hash sequence in the LocalHashTree (in write mode), which helps us understand how often each sequence appears in a specific module. This frequency is represented as Terminals -- https://github.com/llvm/llvm-project/blob/main/llvm/lib/CGData/OutlinedHashTree.cpp#L87.
When combining data from all modules, this terminal count shows the total occurrences of each sequence across all modules.

In this PR, when we create a GlobalOutlinedFunction using CGData from previous runs (in read mode), we initialize a GlobalOccurrenceCount from the Terminals in the global hash tree, which has been merged. This count helps us decide which candidates are most important to outline based on their frequency across all modules.

Copy link
Contributor

@aemerson aemerson Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This count helps us decide which candidates are most important to outline based on their frequency across all modules.

This is I guess the core of my question. As long as you have a size saving, surely you would outline all profitable candidate functions so ordering them seems redundant? I'm probably missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We create an outlining candidate each time a sequence of instructions matches in the global hash tree. These candidates may overlap. As shown in the outline function (https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/MachineOutliner.cpp#L837-L868), we sort these candidates and process them sequentially, discarding any that overlap with previously processed ones. Initially, our global outlining implementation did not utilize this count information. However, we discovered that prioritizing candidates based on their frequency significantly improves size efficiency in real-world workloads.

Although it's theoretically possible to globally order all candidates using the hash tree, we can't access to other modules to determine the best outlining sequence, as modules are fundamentally independent. In this PR, we populate candidates that appear in the current module, match them in the global hash tree, and then order these local instances based on a global heuristic. While this may not be optimal, it has proven effective in our tests.

For more details, you can refer to a unit test related to candidate prioritization in this PR: llvm/test/CodeGen/AArch64/cgdata-read-priority.ll

- Capitalize the comments
- Use Mapper.LegalInstrNumber
- Remove dead code (Sequence)
5c4lar pushed a commit to 5c4lar/llvm-project that referenced this pull request Aug 29, 2024
This patch prepares the NFC groundwork for global outlining using
CGData, which will follow
llvm#90074.

- The `MinRepeats` parameter is now explicitly passed to the
`getOutliningCandidateInfo` function, rather than relying on a default
value of 2. For local outlining, the minimum number of repetitions is
typically 2, but for the global outlining (mentioned above), we will
optimistically create a single `Candidate` for each `OutlinedFunction`
if stable hashes match a specific code sequence. This parameter is
adjusted accordingly in global outlining scenarios.
- I have also implemented `unique_ptr` for `OutlinedFunction` to ensure
safe and efficient memory management within `FunctionList`, avoiding
unnecessary implicit copies.

This depends on llvm#101461.
This is a patch for
https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.
@kyulee-com
Copy link
Contributor Author

Could someone please take another look at this code? It is a crucial component for integrating the global outlining capability into the machine outliner. I've made efforts to ensure that the integration disrupts the existing logic as little as possible. Thanks!

@kyulee-com
Copy link
Contributor Author

I think I've addressed all the comments so far. Could someone please take another look? Thanks!

Copy link
Contributor

@ellishg ellishg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for fixing my nits

@kyulee-com kyulee-com merged commit 0f52545 into llvm:main Sep 10, 2024
8 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 10, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/6643

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: CodeGen/X86/cfi-inserter-check-order.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure < /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll -o /dev/null 2>&1 | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure -o /dev/null
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll
�[1m/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll:7:16: �[0m�[0;1;31merror: �[0m�[1mCHECK-LABEL: expected string not found in input
�[0m; CHECK-LABEL: Pass Arguments:
�[0;1;32m               ^
�[0m�[1m<stdin>:1:1: �[0m�[0;1;30mnote: �[0m�[1mscanning from here
�[0mPass 'Machine Outliner' is not initialized.
�[0;1;32m^
�[0m�[1m<stdin>:8:7: �[0m�[0;1;30mnote: �[0m�[1mpossible intended match here
�[0m0. Program arguments: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure -o /dev/null
�[0;1;32m      ^
�[0m
Input file: <stdin>
Check file: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
�[1m�[0m�[0;1;30m           1: �[0m�[1m�[0;1;46mPass 'Machine Outliner' is not initialized. �[0m
�[0;1;31mlabel:7'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
�[0m�[0;1;30m           2: �[0m�[1m�[0;1;46mVerify if there is a pass dependency cycle. �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           3: �[0m�[1m�[0;1;46mRequired Passes: �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           4: �[0m�[1m�[0;1;46m Machine Module Information �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           5: �[0m�[1m�[0;1;46mllc: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:714: void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected required passes to be initialized"' failed. �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           6: �[0m�[1m�[0;1;46mPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           7: �[0m�[1m�[0;1;46mStack dump: �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~
�[0m�[0;1;30m           8: �[0m�[1m�[0;1;46m0. Program arguments: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure -o /dev/null �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;35mlabel:7'1           ?                                                                                                                                                                               possible intended match
�[0m�[0;1;30m           9: �[0m�[1m�[0;1;46m #0 0x00005e72caa00c60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc+0x209cc60) �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m          10: �[0m�[1m�[0;1;46m #1 0x00005e72ca9fe06f llvm::sys::RunSignalHandlers() (/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc+0x209a06f) �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m          11: �[0m�[1m�[0;1;46m #2 0x00005e72ca9fe1c5 SignalHandler(int) Signals.cpp:0:0 �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m          12: �[0m�[1m�[0;1;46m #3 0x00007b71e1e7c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) �[0m
�[0;1;31mlabel:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 10, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-win-fast running on as-builder-3 while building llvm at step 8 "test-build-unified-tree-check-clang-unit".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/2/builds/6362

Here is the relevant piece of the build log for the reference
Step 8 (test-build-unified-tree-check-clang-unit) failure: test (failure)
******************** TEST 'Clang-Unit :: Interpreter/./ClangReplInterpreterTests.exe/13/26' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\Interpreter\.\ClangReplInterpreterTests.exe-Clang-Unit-12752-13-26.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=26 GTEST_SHARD_INDEX=13 C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\Interpreter\.\ClangReplInterpreterTests.exe
--

Script:
--
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\Interpreter\.\ClangReplInterpreterTests.exe --gtest_filter=InterpreterExtensionsTest.CustomCrossJIT
--
Pass 'Machine Outliner' is not initialized.
Verify if there is a pass dependency cycle.
Required Passes:
	Machine Module Information
unknown file: error: SEH exception with code 0x3221225477 thrown in the test body.
Stack trace:



unknown file
SEH exception with code 0x3221225477 thrown in the test body.
Stack trace:




********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 10, 2024

LLVM Buildbot has detected a new failure on builder llvm-nvptx-nvidia-ubuntu running on as-builder-7 while building llvm at step 6 "test-build-unified-tree-check-llvm".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/4834

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-llvm) failure: test (failure)
******************** TEST 'LLVM :: CodeGen/X86/cfi-inserter-check-order.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure < /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll -o /dev/null 2>&1 | /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll
+ /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure -o /dev/null
+ /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll:7:16: error: CHECK-LABEL: expected string not found in input
; CHECK-LABEL: Pass Arguments:
               ^
<stdin>:1:1: note: scanning from here
Pass 'Machine Outliner' is not initialized.
^
<stdin>:8:7: note: possible intended match here
0. Program arguments: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure -o /dev/null
      ^

Input file: <stdin>
Check file: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: Pass 'Machine Outliner' is not initialized. 
label:7'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: Verify if there is a pass dependency cycle. 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           3: Required Passes: 
label:7'0     ~~~~~~~~~~~~~~~~~
           4:  Machine Module Information 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           5: llc: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:714: void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected required passes to be initialized"' failed. 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           6: PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           7: Stack dump: 
label:7'0     ~~~~~~~~~~~~
           8: 0. Program arguments: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure -o /dev/null 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
label:7'1           ?                                                                                                                                                                                    possible intended match
           9:  #0 0x000075fff5d739b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/lib/libLLVMSupport.so.20.0git+0x1e09b0) 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          10:  #1 0x000075fff5d70dbf llvm::sys::RunSignalHandlers() (/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/lib/libLLVMSupport.so.20.0git+0x1dddbf) 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          11:  #2 0x000075fff5d70f15 SignalHandler(int) Signals.cpp:0:0 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          12:  #3 0x000075fff5442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 10, 2024

LLVM Buildbot has detected a new failure on builder llvm-nvptx64-nvidia-ubuntu running on as-builder-7 while building llvm at step 6 "test-build-unified-tree-check-llvm".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/4836

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-llvm) failure: test (failure)
******************** TEST 'LLVM :: CodeGen/X86/cfi-inserter-check-order.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure < /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll -o /dev/null 2>&1 | /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll
+ /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure -o /dev/null
+ /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll:7:16: error: CHECK-LABEL: expected string not found in input
; CHECK-LABEL: Pass Arguments:
               ^
<stdin>:1:1: note: scanning from here
Pass 'Machine Outliner' is not initialized.
^
<stdin>:8:7: note: possible intended match here
0. Program arguments: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure -o /dev/null
      ^

Input file: <stdin>
Check file: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-check-order.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: Pass 'Machine Outliner' is not initialized. 
label:7'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: Verify if there is a pass dependency cycle. 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           3: Required Passes: 
label:7'0     ~~~~~~~~~~~~~~~~~
           4:  Machine Module Information 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           5: llc: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:714: void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected required passes to be initialized"' failed. 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           6: PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           7: Stack dump: 
label:7'0     ~~~~~~~~~~~~
           8: 0. Program arguments: /home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/llc -mtriple=x86_64-- -O2 -enable-machine-outliner -debug-pass=Structure -o /dev/null 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
label:7'1           ?                                                                                                                                                                                      possible intended match
           9:  #0 0x000073a05d5079b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/lib/libLLVMSupport.so.20.0git+0x1e09b0) 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          10:  #1 0x000073a05d504dbf llvm::sys::RunSignalHandlers() (/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/lib/libLLVMSupport.so.20.0git+0x1dddbf) 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          11:  #2 0x000073a05d504f15 SignalHandler(int) Signals.cpp:0:0 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          12:  #3 0x000073a05cc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

kyulee-com added a commit to kyulee-com/llvm-project that referenced this pull request Sep 10, 2024
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 10, 2024

LLVM Buildbot has detected a new failure on builder clang-ve-ninja running on hpce-ve-main while building llvm at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/12/builds/5502

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/ve-linux.py ...' (failure)
...
[651/652] Running the LLVM regression tests
Unknown option: -C
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
An error occurred retrieving the git revision: Command '['git', '-C', '/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm', 'rev-parse', 'HEAD']' returned non-zero exit status 129.
-- Testing: 55215 tests, 48 workers --
Testing:  0.. 10.. 20.. 30.. 40.
FAIL: LLVM :: CodeGen/X86/machine-outliner-cfi-tail.mir (25408 of 55215)
******************** TEST 'LLVM :: CodeGen/X86/machine-outliner-cfi-tail.mir' FAILED ********************
Exit Code: 2

Command Output (stderr):
--
RUN: at line 2: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/llc -mtriple=x86_64-apple-unknown -run-pass=machine-outliner -verify-machineinstrs /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir -o - | /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/llc -mtriple=x86_64-apple-unknown -run-pass=machine-outliner -verify-machineinstrs /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir -o -
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir
Pass 'Machine Outliner' is not initialized.
Verify if there is a pass dependency cycle.
Required Passes:
	Machine Module Information
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/llc -mtriple=x86_64-apple-unknown -run-pass=machine-outliner -verify-machineinstrs /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir -o -
#0 0x000000000197cbc7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
#1 0x000000000197ad80 llvm::sys::RunSignalHandlers() /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/lib/Support/Signals.cpp:106:18
#2 0x000000000197d28f SignalHandler(int) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
#3 0x00007f784c3e5630 __restore_rt sigaction.c:0:0
#4 0x0000000001215d68 llvm::PassInfo::createPass() const /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/include/llvm/PassInfo.h:88:12
#5 0x0000000001215d68 llvm::PMTopLevelManager::schedulePass(llvm::Pass*) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:715:28
#6 0x000000000076c44a addPass(llvm::legacy::PassManagerBase&, char const*, llvm::StringRef, llvm::TargetPassConfig&) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/tools/llc/llc.cpp:444:7
#7 0x000000000076c44a compileModule(char**, llvm::LLVMContext&) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/tools/llc/llc.cpp:714:13
#8 0x000000000076c44a main /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/tools/llc/llc.cpp:412:22
#9 0x00007f784b3fe555 __libc_start_main /usr/src/debug/glibc-2.17-c758a686/csu/../csu/libc-start.c:300:0
#10 0x0000000000767287 _start (/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/llc+0x767287)
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir

--

********************
Testing:  0.. 10.. 20.. 30.. 40.
FAIL: LLVM :: CodeGen/X86/machine-outliner-cfi-tail-some.mir (25409 of 55215)
******************** TEST 'LLVM :: CodeGen/X86/machine-outliner-cfi-tail-some.mir' FAILED ********************
Exit Code: 2

Command Output (stderr):
Step 8 (check-llvm) failure: check-llvm (failure)
...
[651/652] Running the LLVM regression tests
Unknown option: -C
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
An error occurred retrieving the git revision: Command '['git', '-C', '/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm', 'rev-parse', 'HEAD']' returned non-zero exit status 129.
-- Testing: 55215 tests, 48 workers --
Testing:  0.. 10.. 20.. 30.. 40.
FAIL: LLVM :: CodeGen/X86/machine-outliner-cfi-tail.mir (25408 of 55215)
******************** TEST 'LLVM :: CodeGen/X86/machine-outliner-cfi-tail.mir' FAILED ********************
Exit Code: 2

Command Output (stderr):
--
RUN: at line 2: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/llc -mtriple=x86_64-apple-unknown -run-pass=machine-outliner -verify-machineinstrs /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir -o - | /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/llc -mtriple=x86_64-apple-unknown -run-pass=machine-outliner -verify-machineinstrs /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir -o -
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir
Pass 'Machine Outliner' is not initialized.
Verify if there is a pass dependency cycle.
Required Passes:
	Machine Module Information
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/llc -mtriple=x86_64-apple-unknown -run-pass=machine-outliner -verify-machineinstrs /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir -o -
#0 0x000000000197cbc7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
#1 0x000000000197ad80 llvm::sys::RunSignalHandlers() /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/lib/Support/Signals.cpp:106:18
#2 0x000000000197d28f SignalHandler(int) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
#3 0x00007f784c3e5630 __restore_rt sigaction.c:0:0
#4 0x0000000001215d68 llvm::PassInfo::createPass() const /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/include/llvm/PassInfo.h:88:12
#5 0x0000000001215d68 llvm::PMTopLevelManager::schedulePass(llvm::Pass*) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:715:28
#6 0x000000000076c44a addPass(llvm::legacy::PassManagerBase&, char const*, llvm::StringRef, llvm::TargetPassConfig&) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/tools/llc/llc.cpp:444:7
#7 0x000000000076c44a compileModule(char**, llvm::LLVMContext&) /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/tools/llc/llc.cpp:714:13
#8 0x000000000076c44a main /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/tools/llc/llc.cpp:412:22
#9 0x00007f784b3fe555 __libc_start_main /usr/src/debug/glibc-2.17-c758a686/csu/../csu/libc-start.c:300:0
#10 0x0000000000767287 _start (/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/llc+0x767287)
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/test/CodeGen/X86/machine-outliner-cfi-tail.mir

--

********************
Testing:  0.. 10.. 20.. 30.. 40.
FAIL: LLVM :: CodeGen/X86/machine-outliner-cfi-tail-some.mir (25409 of 55215)
******************** TEST 'LLVM :: CodeGen/X86/machine-outliner-cfi-tail-some.mir' FAILED ********************
Exit Code: 2

Command Output (stderr):

kyulee-com added a commit to kyulee-com/llvm-project that referenced this pull request Sep 10, 2024
@nico
Copy link
Contributor

nico commented Sep 10, 2024

Looks like this is breaking llvm/test/CodeGen/Generic/llc-start-stop.ll on macOS: http://45.33.8.238/macm1/91798/step_10.txt

Please take a look and revert for now if it takes a while to fix.

@kyulee-com
Copy link
Contributor Author

kyulee-com commented Sep 10, 2024

Looks like this is breaking llvm/test/CodeGen/Generic/llc-start-stop.ll on macOS: http://45.33.8.238/macm1/91798/step_10.txt

Please take a look and revert for now if it takes a while to fix.

Thanks for the head-up! I made a forward fix with #108037. Hope this resolves this case, too.

@nico
Copy link
Contributor

nico commented Sep 10, 2024

The forward fix broke check-llvm on linux too: http://45.33.8.238/linux/147290/step_11.txt

kyulee-com pushed a commit to kyulee-com/llvm-project that referenced this pull request Sep 10, 2024
@kyulee-com
Copy link
Contributor Author

The forward fix broke check-llvm on linux too: http://45.33.8.238/linux/147290/step_11.txt

Sorry about the incomplete fix. What about #108047?

@nico
Copy link
Contributor

nico commented Sep 10, 2024

I don't know, it hasn't landed yet. Go ahead and commit I suppose – trunk is already broken, it won't get worse. But if things are still broken then, it's probably time to regroup, revert this and the then-two follow-ups and find a local repro to confirm fixes on.

@kyulee-com
Copy link
Contributor Author

I don't know, it hasn't landed yet. Go ahead and commit I suppose – trunk is already broken, it won't get worse. But if things are still broken then, it's probably time to regroup, revert this and the then-two follow-ups and find a local repro to confirm fixes on.

Sure, I will land it first. If things are not fixed, I will revert the entire change.
By the way, could you approve #108047? Somehow, I can't directly commit it to the main branch, although I have done so before.

kyulee-com added a commit that referenced this pull request Sep 10, 2024
…0074) #108037 (#108047)

The previous `attempt to fix [CGData][MachineOutliner] Global Outlining
(#90074) #108037` was incomplete because the
`ImmutableModuleSummaryIndexWrapperPass` is now optional for the
MachineOutliner pass.

With this fix, the test file `CodeGen/AArch64/O3-pipeline.ll` shows no
changes compared to its state before `[CGData][MachineOutliner] Global
Outlining (#90074)`.

Co-authored-by: Kyungwoo Lee <[email protected]>
@nico
Copy link
Contributor

nico commented Sep 10, 2024

check-llvm is still broken: http://45.33.8.238/linux/147291/step_11.txt

kyulee-com added a commit that referenced this pull request Sep 10, 2024
The previous `Fix for Attempt to fix [CGData][MachineOutliner] Global
Outlining (#90074) #108037 (#108047)` somehow dropped this file.
VitaNuo pushed a commit to VitaNuo/llvm-project that referenced this pull request Sep 12, 2024
This commit introduces support for outlining functions across modules
using codegen data generated from previous codegen. The codegen data
currently manages the outlined hash tree, which records outlining
instances that occurred locally in the past.
    
The machine outliner now operates in one of three modes:

1. CGDataMode::None: This is the default outliner mode that uses the
suffix tree to identify (local) outlining candidates within a module.
This mode is also used by (full)LTO to maintain optimal behavior with
the combined module.
2. CGDataMode::Write (`-codegen-data-generate`): This mode is identical
to the default mode, but it also publishes the stable hash sequences of
instructions in the outlined functions into a local outlined hash tree.
It then encodes this into the `__llvm_outline` section, which will be
dead-stripped at link time.
3. CGDataMode::Read (`-codegen-data-use-path={.cgdata}`): This mode
reads a codegen data file (.cgdata) and initializes a global outlined
hash tree. This tree is used to generate global outlining candidates.
Note that the codegen data file has been post-processed with the raw
`__llvm_outline` sections from all native objects using the
`llvm-cgdata` tool (or a linker, `LLD`, or a new ThinLTO pipeline
later).

This depends on llvm#105398. After
this PR, LLD (llvm#90166) and Clang
(llvm#90304) will follow for each
client side support.
This is a patch for
https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.
VitaNuo pushed a commit to VitaNuo/llvm-project that referenced this pull request Sep 12, 2024
VitaNuo pushed a commit to VitaNuo/llvm-project that referenced this pull request Sep 12, 2024
…vm#90074) llvm#108037 (llvm#108047)

The previous `attempt to fix [CGData][MachineOutliner] Global Outlining
(llvm#90074) llvm#108037` was incomplete because the
`ImmutableModuleSummaryIndexWrapperPass` is now optional for the
MachineOutliner pass.

With this fix, the test file `CodeGen/AArch64/O3-pipeline.ll` shows no
changes compared to its state before `[CGData][MachineOutliner] Global
Outlining (llvm#90074)`.

Co-authored-by: Kyungwoo Lee <[email protected]>
VitaNuo pushed a commit to VitaNuo/llvm-project that referenced this pull request Sep 12, 2024
The previous `Fix for Attempt to fix [CGData][MachineOutliner] Global
Outlining (llvm#90074) llvm#108037 (llvm#108047)` somehow dropped this file.
kyulee-com added a commit that referenced this pull request Sep 15, 2024
It reads raw CG data encoded in the custom section (__llvm_outline) in
object files and merges them into the indexed codegen data file
specified by `-codegen-data-generate-path={path}`.

This depends on #90074.
This is a patch for
https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.
kyulee-com added a commit to kyulee-com/llvm-project that referenced this pull request Sep 15, 2024
It reads raw CG data encoded in the custom section (__llvm_outline) in
object files and merges them into the indexed codegen data file
specified by `-codegen-data-generate-path={path}`.

This depends on llvm#90074.
This is a patch for
https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.
kyulee-com added a commit that referenced this pull request Sep 15, 2024
It reads raw CG data encoded in the custom section (__llvm_outline) in
object files and merges them into the indexed codegen data file
specified by -codegen-data-generate-path={path}.

This depends on #90074.
This is a patch for
https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants