[llvm] [CodeGen][NPM] Add support for -print-regusage in New Pass Manager (PR #169761)
Teja Alaghari via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 26 21:24:39 PST 2025
https://github.com/TejaX-Alaghari created https://github.com/llvm/llvm-project/pull/169761
Legacy pass manager uses `doFinalization()` method called at the end of module processing to print register usage information when `-print-regusage` flag is passed.
This patch attempts to add an alternative mechanism to support this functionality in the NPM.
>From e105e13a1ace170d7e25e604e2a01a8f35aad019 Mon Sep 17 00:00:00 2001
From: vikhegde <vikram.hegde at amd.com>
Date: Mon, 8 Sep 2025 11:37:49 +0530
Subject: [PATCH 1/2] Fixes to be upstreamed - 10
1. add support for DumpRegUsage in NPM (currntly I have added it in the destructor of RegisterUsageInfo, this seems to work but im not sure if it has any side effects)
---
llvm/include/llvm/CodeGen/RegisterUsageInfo.h | 2 ++
llvm/lib/CodeGen/RegisterUsageInfo.cpp | 7 +++++++
2 files changed, 9 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/RegisterUsageInfo.h b/llvm/include/llvm/CodeGen/RegisterUsageInfo.h
index 9b0d30426f1d3..ada87e5632b4c 100644
--- a/llvm/include/llvm/CodeGen/RegisterUsageInfo.h
+++ b/llvm/include/llvm/CodeGen/RegisterUsageInfo.h
@@ -34,6 +34,8 @@ class TargetMachine;
class PhysicalRegisterUsageInfo {
public:
+
+ ~PhysicalRegisterUsageInfo();
/// Set TargetMachine which is used to print analysis.
void setTargetMachine(const TargetMachine &TM);
diff --git a/llvm/lib/CodeGen/RegisterUsageInfo.cpp b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
index 2ef380fc7cad4..d48280642da52 100644
--- a/llvm/lib/CodeGen/RegisterUsageInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
@@ -56,6 +56,13 @@ bool PhysicalRegisterUsageInfo::doFinalization(Module &M) {
return false;
}
+PhysicalRegisterUsageInfo::~PhysicalRegisterUsageInfo() {
+ if (DumpRegUsage)
+ print(errs());
+
+ RegMasks.shrink_and_clear();
+}
+
void PhysicalRegisterUsageInfo::storeUpdateRegUsageInfo(
const Function &FP, ArrayRef<uint32_t> RegMask) {
RegMasks[&FP] = RegMask;
>From 15777d6c065bfd9aaab3c3371a8dc9822fd626d2 Mon Sep 17 00:00:00 2001
From: Teja Alaghari <teja.alaghari at amd.com>
Date: Thu, 27 Nov 2025 10:42:36 +0530
Subject: [PATCH 2/2] Check TM validity before printing
---
llvm/include/llvm/CodeGen/RegisterUsageInfo.h | 1 -
llvm/lib/CodeGen/RegisterUsageInfo.cpp | 10 ++++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/RegisterUsageInfo.h b/llvm/include/llvm/CodeGen/RegisterUsageInfo.h
index ada87e5632b4c..04acaf380405e 100644
--- a/llvm/include/llvm/CodeGen/RegisterUsageInfo.h
+++ b/llvm/include/llvm/CodeGen/RegisterUsageInfo.h
@@ -34,7 +34,6 @@ class TargetMachine;
class PhysicalRegisterUsageInfo {
public:
-
~PhysicalRegisterUsageInfo();
/// Set TargetMachine which is used to print analysis.
void setTargetMachine(const TargetMachine &TM);
diff --git a/llvm/lib/CodeGen/RegisterUsageInfo.cpp b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
index d48280642da52..48466381f4d3e 100644
--- a/llvm/lib/CodeGen/RegisterUsageInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
@@ -57,10 +57,12 @@ bool PhysicalRegisterUsageInfo::doFinalization(Module &M) {
}
PhysicalRegisterUsageInfo::~PhysicalRegisterUsageInfo() {
- if (DumpRegUsage)
- print(errs());
-
- RegMasks.shrink_and_clear();
+ // As doFinalization() is not called for analysis results in the new PM,
+ // we print the register usage information here.
+ if (DumpRegUsage && TM)
+ print(errs());
+
+ RegMasks.shrink_and_clear();
}
void PhysicalRegisterUsageInfo::storeUpdateRegUsageInfo(
More information about the llvm-commits
mailing list