[llvm] Add and call `AMDGPUMCResourceInfo::reset` method (PR #110818)

Thomas Symalla via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 03:31:35 PDT 2024


https://github.com/tsymalla created https://github.com/llvm/llvm-project/pull/110818

When compiling multiple pipelines, the `MCRegisterInfo` instance in `AMDGPUAsmPrinter` gets re-used even after finalization, so it calls `finalize()` multiple times.

Add a reset method and call it in
`AMDGPUAsmPrinter::doInitialization`.

Different approach would be to make it a `unique_ptr`.

>From 821d52c02f16f2e8d39cd25ebd54c30f22bce112 Mon Sep 17 00:00:00 2001
From: Thomas Symalla <tsymalla at amd.com>
Date: Wed, 2 Oct 2024 12:27:41 +0200
Subject: [PATCH] Add and call `AMDGPUMCResourceInfo::reset` method

When compiling multiple pipelines, the `MCRegisterInfo` instance in
`AMDGPUAsmPrinter` gets re-used even after finalization, so it calls
`finalize()` multiple times.

Add a reset method and call it in
`AMDGPUAsmPrinter::doInitialization`.
---
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp     | 3 +++
 llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp | 7 +++++++
 llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.h   | 2 ++
 3 files changed, 12 insertions(+)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index 4f6633d8027c70..8cc2132a2e6fe9 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -358,6 +358,9 @@ bool AMDGPUAsmPrinter::doInitialization(Module &M) {
       report_fatal_error("Unexpected code object version");
     }
   }
+
+  RI.reset();
+  
   return AsmPrinter::doInitialization(M);
 }
 
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
index f608a9a4f470fa..8293c998c05c76 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
@@ -71,6 +71,13 @@ void MCResourceInfo::assignMaxRegs(MCContext &OutContext) {
   assignMaxRegSym(MaxSGPRSym, MaxSGPR);
 }
 
+void MCResourceInfo::reset() {
+  Finalized = false;
+  MaxVGPR = 0;
+  MaxAGPR = 0;
+  MaxSGPR = 0;
+}
+
 void MCResourceInfo::finalize(MCContext &OutContext) {
   assert(!Finalized && "Cannot finalize ResourceInfo again.");
   Finalized = true;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.h b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.h
index 08c0c106d5aa9b..9f7f4b1b8f75ff 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.h
@@ -75,6 +75,8 @@ class MCResourceInfo {
   const MCExpr *getSymRefExpr(StringRef FuncName, ResourceInfoKind RIK,
                               MCContext &Ctx);
 
+  void reset();
+  
   // Resolves the final symbols that requires the inter-function resource info
   // to be resolved.
   void finalize(MCContext &OutContext);



More information about the llvm-commits mailing list