llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: Yaxun (Sam) Liu (yxsamliu)

<details>
<summary>Changes</summary>

This reverts commit 85e903099313aa5ea98d175698aaa40e27a0d743.

The change breaks MSVC builds because an inline SmallPtrSet operation
requires a complete DILocation type. It also causes expensive-check
builds to report that the DXIL pretty-printer modifies its input
without reporting it.

Revert while fixes and test coverage are prepared.

Buildbot failure: https://lab.llvm.org/buildbot/#/builders/2/builds/60795
Buildbot failure: https://lab.llvm.org/buildbot/#/builders/187/builds/23268


---

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


75 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+2-5) 
- (modified) clang/tools/cir-translate/cir-translate.cpp (-1) 
- (modified) clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp (+1-4) 
- (modified) clang/tools/clang-import-test/clang-import-test.cpp (+1-3) 
- (modified) flang/include/flang/Optimizer/CodeGen/CodeGen.h (+3-5) 
- (modified) flang/lib/Frontend/FrontendActions.cpp (+3-3) 
- (modified) llvm/include/llvm/CodeGen/MachineModuleSlotTracker.h (+12-13) 
- (modified) llvm/include/llvm/IR/IRPrintingPasses.h (-5) 
- (modified) llvm/include/llvm/IR/Metadata.h (+5-5) 
- (modified) llvm/include/llvm/IR/Module.h (-5) 
- (modified) llvm/include/llvm/IR/ModuleSlotTracker.h (+19-33) 
- (modified) llvm/include/llvm/IRPrinter/IRPrintingPasses.h (+2-5) 
- (modified) llvm/lib/CodeGen/MIRParser/MIParser.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/MIRPrintingPass.cpp (-16) 
- (modified) llvm/lib/CodeGen/MachineBasicBlock.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/MachineModuleSlotTracker.cpp (+55-56) 
- (modified) llvm/lib/CodeGen/MachineOperand.cpp (+1-1) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+180-237) 
- (modified) llvm/lib/IR/Core.cpp (-2) 
- (modified) llvm/lib/IR/IRPrintingPasses.cpp (+25-46) 
- (modified) llvm/lib/IR/LLVMContextImpl.cpp (-9) 
- (modified) llvm/lib/IR/LLVMContextImpl.h (-18) 
- (modified) llvm/lib/IR/Metadata.cpp (-17) 
- (modified) llvm/lib/IR/MetadataImpl.h (-2) 
- (modified) llvm/lib/IR/SSAContext.cpp (+1-1) 
- (modified) llvm/lib/IRPrinter/IRPrintingPasses.cpp (+6-14) 
- (modified) llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp (+14-92) 
- (modified) llvm/test/CodeGen/DirectX/DebugInfo/di-globalvariable.ll (-7) 
- (modified) llvm/test/CodeGen/Hexagon/swp-no-alias.mir (+4-4) 
- (modified) llvm/test/CodeGen/MIR/AMDGPU/instr-mmra.mir (+1-1) 
- (modified) llvm/test/CodeGen/MIR/AMDGPU/machine-metadata.mir (+6-6) 
- (modified) llvm/test/CodeGen/MIR/X86/instr-heap-alloc-operands.mir (+1-1) 
- (modified) llvm/test/CodeGen/MIR/X86/instr-pcsections.mir (+1-1) 
- (modified) llvm/test/CodeGen/MIR/X86/instructions-debug-location.mir (+7-7) 
- (modified) llvm/test/CodeGen/MIR/X86/machine-metadata.mir (+18-18) 
- (modified) llvm/test/CodeGen/MIR/X86/mem-cache-hint.mir (+2-2) 
- (modified) llvm/test/CodeGen/MIR/X86/memory-operands.mir (+5-5) 
- (modified) llvm/test/CodeGen/MIR/X86/metadata-operands.mir (+1-1) 
- (modified) llvm/test/CodeGen/MIR/X86/pr38773.mir (+2-2) 
- (modified) llvm/test/CodeGen/MIR/X86/stack-object-debug-info.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/AArch64/no-dbg-value-after-terminator.mir 
(+1-1) 
- (modified) llvm/test/Other/legacy-callgraph-scc-pass-printer.ll (+1-12) 
- (removed) llvm/test/Other/print-changed-persistent-metadata-ids.ll (-77) 
- (removed) llvm/test/Other/print-persistent-metadata-ids.ll (-94) 
- (modified) 
llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/loop-distribute.ll.expected
 (+3-3) 
- (modified) 
llvm/test/tools/llvm-debuginfo-analyzer/IR/01-ir-print-basic-details.test 
(+11-11) 
- (modified) 
llvm/test/tools/llvm-debuginfo-analyzer/IR/01-ir-select-logical-elements.test 
(+8-8) 
- (modified) 
llvm/test/tools/llvm-debuginfo-analyzer/IR/02-ir-logical-lines.test (+2-2) 
- (modified) 
llvm/test/tools/llvm-debuginfo-analyzer/IR/06-ir-full-logical-view.test 
(+11-11) 
- (modified) llvm/tools/llvm-dis/llvm-dis.cpp (-1) 
- (modified) llvm/tools/llvm-extract/llvm-extract.cpp (+2-4) 
- (modified) llvm/tools/llvm-link/llvm-link.cpp (-1) 
- (modified) llvm/tools/llvm-reduce/ReducerWorkItem.cpp (+1-8) 
- (modified) llvm/tools/llvm-split/llvm-split.cpp (+3-4) 
- (modified) llvm/tools/llvm-stress/llvm-stress.cpp (-1) 
- (modified) llvm/tools/opt/NewPMDriver.cpp (+1-2) 
- (modified) llvm/tools/opt/optdriver.cpp (+3-4) 
- (modified) llvm/tools/verify-uselistorder/verify-uselistorder.cpp (+4-5) 
- (modified) llvm/unittests/AsmParser/AsmParserTest.cpp (-33) 
- (modified) llvm/unittests/IR/AsmWriterTest.cpp (-124) 
- (modified) llvm/unittests/IR/MetadataTest.cpp (+11-7) 
- (modified) llvm/unittests/IR/ModuleTest.cpp (-55) 
- (modified) llvm/unittests/MIR/MachineMetadata.cpp (+34-84) 
- (modified) mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp (-1) 
- (modified) mlir/test/Target/LLVMIR/Import/import-failure.ll (+12-12) 
- (modified) polly/test/ForwardOpTree/atax.ll (+8-8) 
- (modified) polly/test/ForwardOpTree/jacobi-1d.ll (+4-4) 
- (modified) polly/test/ScopInfo/preserve-equiv-class-order-in-basic_block.ll 
(+2-2) 
- (modified) polly/test/ScopInfo/stmt_split_exit_of_region_stmt.ll (+1-1) 
- (modified) polly/test/ScopInfo/stmt_split_no_after_split.ll (+1-1) 
- (modified) polly/test/ScopInfo/stmt_split_no_dependence.ll (+1-1) 
- (modified) polly/test/ScopInfo/stmt_split_phi_in_beginning_bb.ll (+1-1) 
- (modified) polly/test/ScopInfo/stmt_split_phi_in_stmt.ll (+1-1) 
- (modified) polly/test/ScopInfo/stmt_split_scalar_dependence.ll (+1-1) 
- (modified) polly/test/ScopInfo/stmt_split_within_loop.ll (+1-1) 


``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 086f886be4390..6aa6bc1bd41e8 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1166,8 +1166,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
             *OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr));
       } else if (Action == Backend_EmitLL) {
         MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
-                                    /*EmitLTOSummary=*/true,
-                                    /*ShouldRenumberMetadata=*/true));
+                                    /*EmitLTOSummary=*/true));
       }
     } else {
       // Emit a module summary by default for Regular LTO except for ld64
@@ -1185,8 +1184,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
                                       EmitLTOSummary));
       } else if (Action == Backend_EmitLL) {
         MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
-                                    EmitLTOSummary,
-                                    /*ShouldRenumberMetadata=*/true));
+                                    EmitLTOSummary));
       }
     }
 
@@ -1458,7 +1456,6 @@ runThinLTOBackend(CompilerInstance &CI, 
ModuleSummaryIndex *CombinedIndex,
     break;
   case Backend_EmitLL:
     Conf.PreCodeGenModuleHook = [&](size_t Task, const llvm::Module &Mod) {
-      M->renumberMetadataForAssembly();
       M->print(*OS, nullptr, CGOpts.EmitLLVMUseLists);
       return false;
     };
diff --git a/clang/tools/cir-translate/cir-translate.cpp 
b/clang/tools/cir-translate/cir-translate.cpp
index a58512e3fca22..4452741d7433e 100644
--- a/clang/tools/cir-translate/cir-translate.cpp
+++ b/clang/tools/cir-translate/cir-translate.cpp
@@ -165,7 +165,6 @@ void registerToLLVMTranslation() {
                                                       enableOpenMP);
         if (!llvmModule)
           return mlir::failure();
-        llvmModule->renumberMetadataForAssembly();
         llvmModule->print(output, nullptr);
         return mlir::success();
       },
diff --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp 
b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index 1c745bffe00c0..942e35c30e19f 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -103,10 +103,7 @@ static void RunOptimizationPasses(raw_ostream &OS, Module 
&M,
   PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
 
   ModulePassManager MPM = PB.buildPerModuleDefaultPipeline(OL);
-  MPM.addPass(PrintModulePass(OS, /*Banner=*/"",
-                              /*ShouldPreserveUseListOrder=*/false,
-                              /*EmitSummaryIndex=*/false,
-                              /*ShouldRenumberMetadata=*/true));
+  MPM.addPass(PrintModulePass(OS));
 
   MPM.run(M, MAM);
 }
diff --git a/clang/tools/clang-import-test/clang-import-test.cpp 
b/clang/tools/clang-import-test/clang-import-test.cpp
index bcb5d2bdb8952..8e83687d3e96a 100644
--- a/clang/tools/clang-import-test/clang-import-test.cpp
+++ b/clang/tools/clang-import-test/clang-import-test.cpp
@@ -338,10 +338,8 @@ llvm::Expected<CIAndOrigins> Parse(const std::string &Path,
   if (llvm::Error PE = ParseSource(Path, CI.getCompilerInstance(), Consumers))
     return std::move(PE);
   CI.getDiagnosticClient().EndSourceFile();
-  if (ShouldDumpIR) {
-    CG.GetModule()->renumberMetadataForAssembly();
+  if (ShouldDumpIR)
     CG.GetModule()->print(llvm::outs(), nullptr);
-  }
   if (CI.getDiagnosticClient().getNumErrors())
     return llvm::make_error<llvm::StringError>(
         "Errors occurred while parsing the expression.", std::error_code());
diff --git a/flang/include/flang/Optimizer/CodeGen/CodeGen.h 
b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
index 6ef575f5391d9..1d36788fb84f9 100644
--- a/flang/include/flang/Optimizer/CodeGen/CodeGen.h
+++ b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
@@ -90,11 +90,9 @@ using LLVMIRLoweringPrinter =
 
 /// Convert the LLVM IR dialect to LLVM-IR proper
 std::unique_ptr<mlir::Pass> createLLVMDialectToLLVMPass(
-    llvm::raw_ostream &output, LLVMIRLoweringPrinter printer =
-                                   [](llvm::Module &m, llvm::raw_ostream &out) 
{
-                                     m.renumberMetadataForAssembly();
-                                     m.print(out, nullptr);
-                                   });
+    llvm::raw_ostream &output,
+    LLVMIRLoweringPrinter printer =
+        [](llvm::Module &m, llvm::raw_ostream &out) { m.print(out, nullptr); 
});
 
 /// Populate the given list with patterns that convert from FIR to LLVM.
 void populateFIRToLLVMConversionPatterns(
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 108b1b4559d48..35e0e4004d9a0 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1094,9 +1094,9 @@ void 
CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
             os, /*ShouldPreserveUseListOrder=*/false, emitSummary));
       }
     } else if (action == BackendActionTy::Backend_EmitLL) {
-      mpm.addPass(llvm::PrintModulePass(
-          os, /*Banner=*/"", /*ShouldPreserveUseListOrder=*/false, emitSummary,
-          /*ShouldRenumberMetadata=*/true));
+      mpm.addPass(llvm::PrintModulePass(os, /*Banner=*/"",
+                                        /*ShouldPreserveUseListOrder=*/false,
+                                        emitSummary));
     }
   }
 
diff --git a/llvm/include/llvm/CodeGen/MachineModuleSlotTracker.h 
b/llvm/include/llvm/CodeGen/MachineModuleSlotTracker.h
index 1cb15f9cc172d..666b3caf67e27 100644
--- a/llvm/include/llvm/CodeGen/MachineModuleSlotTracker.h
+++ b/llvm/include/llvm/CodeGen/MachineModuleSlotTracker.h
@@ -10,13 +10,12 @@
 #define LLVM_CODEGEN_MACHINEMODULESLOTTRACKER_H
 
 #include "llvm/ADT/STLFunctionalExtras.h"
-#include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/IR/ModuleSlotTracker.h"
 #include "llvm/Support/Compiler.h"
 
 namespace llvm {
 
+class AbstractSlotTrackerStorage;
 class Function;
 class MachineModuleInfo;
 class MachineFunction;
@@ -25,24 +24,24 @@ class Module;
 using MFGetterFnT = function_ref<MachineFunction *(const Function &)>;
 
 class LLVM_ABI MachineModuleSlotTracker : public ModuleSlotTracker {
+  const Function &TheFunction;
   const MachineFunction *TheMF;
-  MachineMDNodeListType MachineMDNodes;
-  SmallPtrSet<const DILocation *, 4> InlineDebugLocations;
+  unsigned MDNStartSlot = 0, MDNEndSlot = 0;
 
-  void collectMachineFunctionMetadata(
-      SmallVectorImpl<const MDNode *> &Metadata, const MachineFunction &MF,
-      SmallVectorImpl<const MDNode *> *DebugLocations = nullptr) const;
+  void processMachineFunctionMetadata(AbstractSlotTrackerStorage *AST,
+                                      const MachineFunction &MF);
+  void processMachineModule(AbstractSlotTrackerStorage *AST, const Module *M,
+                            bool ShouldInitializeAllMetadata);
+  void processMachineFunction(AbstractSlotTrackerStorage *AST,
+                              const Function *F,
+                              bool ShouldInitializeAllMetadata);
 
 public:
-  MachineModuleSlotTracker(MFGetterFnT Fn, const MachineFunction *MF);
+  MachineModuleSlotTracker(MFGetterFnT Fn, const MachineFunction *MF,
+                           bool ShouldInitializeAllMetadata = true);
   ~MachineModuleSlotTracker() override;
 
-  /// Renumber module and machine metadata for canonical MIR output.
-  void renumberMetadataForAssembly();
   void collectMachineMDNodes(MachineMDNodeListType &L) const;
-  bool shouldPrintDebugLocationInline(const DILocation *DL) const override {
-    return InlineDebugLocations.contains(DL);
-  }
 };
 
 } // namespace llvm
diff --git a/llvm/include/llvm/IR/IRPrintingPasses.h 
b/llvm/include/llvm/IR/IRPrintingPasses.h
index 0eb60f55f74c3..1b2d38d6190e9 100644
--- a/llvm/include/llvm/IR/IRPrintingPasses.h
+++ b/llvm/include/llvm/IR/IRPrintingPasses.h
@@ -31,11 +31,6 @@ LLVM_ABI ModulePass *
 createPrintModulePass(raw_ostream &OS, const std::string &Banner = "",
                       bool ShouldPreserveUseListOrder = false);
 
-LLVM_ABI ModulePass *createPrintModulePass(raw_ostream &OS,
-                                           const std::string &Banner,
-                                           bool ShouldPreserveUseListOrder,
-                                           bool ShouldRenumberMetadata);
-
 /// Create and return a pass that prints functions to the specified
 /// \c raw_ostream as they are processed.
 LLVM_ABI FunctionPass *createPrintFunctionPass(raw_ostream &OS,
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index a53cb63ed59cf..5b458fa14f0b1 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -1079,11 +1079,11 @@ class MDNode : public Metadata {
   /// Explicity set alignment because bitfields by default have an
   /// alignment of 1 on z/OS.
   struct alignas(alignof(size_t)) Header {
-    uint32_t IsResizable : 1;
-    uint32_t IsLarge : 1;
-    uint32_t SmallSize : 4;
-    uint32_t SmallNumOps : 4;
-    uint32_t MetadataPrintID;
+    size_t IsResizable : 1;
+    size_t IsLarge : 1;
+    size_t SmallSize : 4;
+    size_t SmallNumOps : 4;
+    size_t : sizeof(size_t) * CHAR_BIT - 10;
 
     unsigned NumUnresolved = 0;
     using LargeStorageVector = SmallVector<MDOperand, 0>;
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 1b22ac79f2d51..6090644f7a12f 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -987,11 +987,6 @@ class LLVM_ABI Module {
              bool ShouldPreserveUseListOrder = false,
              bool IsForDebug = false) const;
 
-  /// Renumber the IDs stored in metadata nodes into canonical assembly order.
-  /// This mutates the IDs and should only be used immediately before final
-  /// assembly output.
-  void renumberMetadataForAssembly();
-
   /// Dump the module to stderr (for debugging).
   void dump() const;
 
diff --git a/llvm/include/llvm/IR/ModuleSlotTracker.h 
b/llvm/include/llvm/IR/ModuleSlotTracker.h
index b92bd16084b06..a3882a81e1177 100644
--- a/llvm/include/llvm/IR/ModuleSlotTracker.h
+++ b/llvm/include/llvm/IR/ModuleSlotTracker.h
@@ -9,12 +9,11 @@
 #ifndef LLVM_IR_MODULESLOTTRACKER_H
 #define LLVM_IR_MODULESLOTTRACKER_H
 
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include <functional>
 #include <memory>
 #include <utility>
+#include <vector>
 
 namespace llvm {
 
@@ -22,7 +21,6 @@ class Module;
 class Function;
 class SlotTracker;
 class Value;
-class DILocation;
 class MDNode;
 
 /// Abstract interface of slot tracker storage.
@@ -30,6 +28,8 @@ class LLVM_ABI AbstractSlotTrackerStorage {
 public:
   virtual ~AbstractSlotTrackerStorage();
 
+  virtual unsigned getNextMetadataSlot() = 0;
+
   virtual void createMetadataSlot(const MDNode *) = 0;
   virtual int getMetadataSlot(const MDNode *) = 0;
 };
@@ -43,37 +43,20 @@ class LLVM_ABI AbstractSlotTrackerStorage {
 /// If the IR changes from underneath \a ModuleSlotTracker, strings like
 /// "<badref>" will be printed, or, worse, the wrong slots entirely.
 class LLVM_ABI ModuleSlotTracker {
-public:
-  using MachineMDNodeListType =
-      SmallVector<std::pair<unsigned, const MDNode *>, 0>;
-
-private:
   /// Storage for a slot tracker.
   std::unique_ptr<SlotTracker> MachineStorage;
   bool ShouldCreateStorage = false;
+  bool ShouldInitializeAllMetadata = false;
 
   const Module *M = nullptr;
   const Function *F = nullptr;
   SlotTracker *Machine = nullptr;
 
-  std::function<void(AbstractSlotTrackerStorage *, const Module *)>
+  std::function<void(AbstractSlotTrackerStorage *, const Module *, bool)>
       ProcessModuleHookFn;
-  std::function<void(AbstractSlotTrackerStorage *, const Function *)>
+  std::function<void(AbstractSlotTrackerStorage *, const Function *, bool)>
       ProcessFunctionHookFn;
 
-protected:
-  /// Renumber module metadata and then additional metadata for canonical
-  /// assembly output.
-  void renumberMetadataForAssembly(
-      ArrayRef<const MDNode *> AdditionalMetadata,
-      MachineMDNodeListType *AdditionalMetadataNodes = nullptr) const;
-
-  /// Collect metadata reachable from \p AdditionalMetadata but not from the
-  /// module.
-  void collectAdditionalMetadata(
-      ArrayRef<const MDNode *> AdditionalMetadata,
-      MachineMDNodeListType &AdditionalMetadataNodes) const;
-
 public:
   /// Wrap a preinitialized SlotTracker.
   ModuleSlotTracker(SlotTracker &Machine, const Module *M,
@@ -81,8 +64,13 @@ class LLVM_ABI ModuleSlotTracker {
 
   /// Construct a slot tracker from a module.
   ///
-  /// If \a M is \c nullptr, uses a null slot tracker.
-  explicit ModuleSlotTracker(const Module *M);
+  /// If \a M is \c nullptr, uses a null slot tracker.  Otherwise, initializes
+  /// a slot tracker, and initializes all metadata slots.  \c
+  /// ShouldInitializeAllMetadata defaults to true because this is expected to
+  /// be shared between multiple callers, and otherwise MDNode references will
+  /// not match up.
+  explicit ModuleSlotTracker(const Module *M,
+                             bool ShouldInitializeAllMetadata = true);
 
   /// Destructor to clean up storage.
   virtual ~ModuleSlotTracker();
@@ -107,16 +95,14 @@ class LLVM_ABI ModuleSlotTracker {
   int getLocalSlot(const Value *V);
 
   void setProcessHook(
-      std::function<void(AbstractSlotTrackerStorage *, const Module *)>);
-  void setProcessHook(
-      std::function<void(AbstractSlotTrackerStorage *, const Function *)>);
+      std::function<void(AbstractSlotTrackerStorage *, const Module *, bool)>);
+  void setProcessHook(std::function<void(AbstractSlotTrackerStorage *,
+                                         const Function *, bool)>);
 
-  void collectMDNodes(MachineMDNodeListType &L) const;
+  using MachineMDNodeListType =
+      std::vector<std::pair<unsigned, const MDNode *>>;
 
-  /// Return whether a debug location should be printed inline instead of by 
ID.
-  virtual bool shouldPrintDebugLocationInline(const DILocation *) const {
-    return false;
-  }
+  void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) 
const;
 };
 
 } // end namespace llvm
diff --git a/llvm/include/llvm/IRPrinter/IRPrintingPasses.h 
b/llvm/include/llvm/IRPrinter/IRPrintingPasses.h
index 56fdd94187dd3..e574d94ca2f22 100644
--- a/llvm/include/llvm/IRPrinter/IRPrintingPasses.h
+++ b/llvm/include/llvm/IRPrinter/IRPrintingPasses.h
@@ -35,16 +35,13 @@ class PrintModulePass : public 
RequiredPassInfoMixin<PrintModulePass> {
   std::string Banner;
   bool ShouldPreserveUseListOrder;
   bool EmitSummaryIndex;
-  bool ShouldRenumberMetadata;
 
 public:
   LLVM_ABI PrintModulePass();
-  /// If \p ShouldRenumberMetadata, renumber metadata for canonical assembly
-  /// output before printing.
   LLVM_ABI PrintModulePass(raw_ostream &OS, const std::string &Banner = "",
                            bool ShouldPreserveUseListOrder = false,
-                           bool EmitSummaryIndex = false,
-                           bool ShouldRenumberMetadata = false);
+                           bool EmitSummaryIndex = false);
+
   LLVM_ABI PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
 };
 
diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp 
b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
index ef4927e2c4ee3..a9caf95a32ef9 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
@@ -360,7 +360,7 @@ static void mapValueToSlot(const Value *V, 
ModuleSlotTracker &MST,
 /// Creates the mapping from slot numbers to function's unnamed IR values.
 static void initSlots2Values(const Function &F,
                              DenseMap<unsigned, const Value *> &Slots2Values) {
-  ModuleSlotTracker MST(F.getParent());
+  ModuleSlotTracker MST(F.getParent(), /*ShouldInitializeAllMetadata=*/false);
   MST.incorporateFunction(F);
   for (const auto &Arg : F.args())
     mapValueToSlot(&Arg, MST, Slots2Values);
@@ -3813,7 +3813,7 @@ bool MIParser::parseMMRA(MDNode *&Node) {
 static void initSlots2BasicBlocks(
     const Function &F,
     DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {
-  ModuleSlotTracker MST(F.getParent());
+  ModuleSlotTracker MST(F.getParent(), /*ShouldInitializeAllMetadata=*/false);
   MST.incorporateFunction(F);
   for (const auto &BB : F) {
     if (BB.hasName())
diff --git a/llvm/lib/CodeGen/MIRPrintingPass.cpp 
b/llvm/lib/CodeGen/MIRPrintingPass.cpp
index 5f6537cdd8c13..f5e455a520151 100644
--- a/llvm/lib/CodeGen/MIRPrintingPass.cpp
+++ b/llvm/lib/CodeGen/MIRPrintingPass.cpp
@@ -12,20 +12,16 @@
 
//===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/MIRPrinter.h"
-#include "llvm/CodeGen/MachineFunctionAnalysis.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
-#include "llvm/CodeGen/MachineModuleSlotTracker.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/VirtRegMap.h"
 #include "llvm/IR/Function.h"
-#include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
 
 using namespace llvm;
 
 PreservedAnalyses PrintMIRPreparePass::run(Module &M, ModuleAnalysisManager &) 
{
-  M.renumberMetadataForAssembly();
   printMIR(OS, M);
   return PreservedAnalyses::all();
 }
@@ -36,14 +32,6 @@ PreservedAnalyses PrintMIRPass::run(MachineFunction &MF,
                   .getManager();
 
   const VirtRegMap *VRM = MFAM.getCachedResult<VirtRegMapAnalysis>(MF);
-  MachineModuleSlotTracker MST(
-      [&](const Function &F) {
-        return &FAM.getResult<MachineFunctionAnalysis>(
-                       const_cast<Function &>(F))
-                    .getMF();
-      },
-      &MF);
-  MST.renumberMetadataForAssembly();
   printMIR(OS, FAM, MF, VRM);
   return PreservedAnalyses::all();
 }
@@ -79,16 +67,12 @@ struct MIRPrintingPass : public MachineFunctionPass {
     if (auto *W = getAnalysisIfAvailable<VirtRegMapWrapperLegacy>())
       VRM = &W->getVRM();
 
-    MachineModuleSlotTracker MST(
-        [&](const Function &F) { return MMI->getMachineFunction(F); }, &MF);
-    MST.renumberMetadataForAssembly();
     printMIR(StrOS, *MMI, MF, VRM);
     MachineFunctions.append(Str);
     return false;
   }
 
   bool doFinalization(Module &M) override {
-    M.renumberMetadataForAssembly();
     printMIR(OS, M);
     OS << MachineFunctions;
     return false;
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp 
b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index b58a11efd103c..08a67935b52f5 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -503,7 +503,7 @@ void MachineBasicBlock::printName(raw_ostream &os, unsigned 
printNameFlags,
       if (moduleSlotTracker) {
         slot = moduleSlotTracker->getLocalSlot(bb);
       } else if (bb->getParent()) {
-        ModuleSlotTracker tmpTracker(bb->getModule());
+        ModuleSlotTracker tmpTracker(bb->getModule(), false);
         tmpTracker.incorporateFunction(*bb->getParent());
         slot = tmpTracker.getLocalSlot(bb);
       }
diff --git a/llvm/lib/CodeGen/MachineModuleSlotTracker.cpp 
b/llvm/lib/CodeGen/MachineModuleSlotTracker.cpp
index f688f2b8b61aa..e08b03eb4d70c 100644
--- a/llvm/lib/CodeGen/MachineModuleSlotTracker.cpp
+++ b/llvm/lib/CodeGen/MachineModuleSlotTracker.cpp
@@ -16,93 +16,92 @@
 
 using namespace llvm;
 
-void MachineModuleSlotTracker::collectMachineFunctionMetadata(
-    SmallVectorImpl<const MDNode *> &Metadata, const MachineFunction &MF,
-    SmallVectorImpl<const MDNode *> *DebugLocations) const {
+void MachineModuleSlotTracker::processMachineFunctionMetadata(
+    AbstractSlotTrackerStorage *AST, const MachineFunction &MF) {
+  // Create metadata created within the backend.
   for (const MachineBasicBlock &MBB : MF)
     for (const MachineInstr &MI : MBB.instrs()) {
-      if (DebugLocations)
-        if (DebugLoc DL = MI.getDebugLoc())
-          DebugLocations->push_back(DL.getAsMDNode());
-
       if (MDNode *N = MI.getHeapAllocMarker())
-        Metadata.push_back(N);
+        AST->createMetadataSlot(N);
       if (MDNode *N = MI.getPCSections())
-        Metadata.push_back(N);
+        AST->createMetadataSlot(N);
   ...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/220334
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to