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

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


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

>From ea4563710b24d6497b2dd655f81e8c62019fc5d7 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::doFinalization`.
---
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp     | 3 +++
 llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp | 2 ++
 llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.h   | 2 ++
 3 files changed, 7 insertions(+)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index 4f6633d8027c70..974f1c80d95530 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -358,6 +358,7 @@ bool AMDGPUAsmPrinter::doInitialization(Module &M) {
       report_fatal_error("Unexpected code object version");
     }
   }
+
   return AsmPrinter::doInitialization(M);
 }
 
@@ -511,6 +512,8 @@ bool AMDGPUAsmPrinter::doFinalization(Module &M) {
   for (Function &F : M.functions())
     validateMCResourceInfo(F);
 
+  RI.reset();
+
   return AsmPrinter::doFinalization(M);
 }
 
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
index f608a9a4f470fa..1de6bf1631a25b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
@@ -71,6 +71,8 @@ void MCResourceInfo::assignMaxRegs(MCContext &OutContext) {
   assignMaxRegSym(MaxSGPRSym, MaxSGPR);
 }
 
+void MCResourceInfo::reset() { *this = MCResourceInfo(); }
+
 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