[llvm] [VirtRegMap] Replace a single value enum with a static constexpr member variable. NFC (PR #109010)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 09:52:17 PDT 2024


https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/109010

>From f815f7e731e534a1d2b74bde1834af0e9bf16ecf Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 17 Sep 2024 09:10:49 -0700
Subject: [PATCH 1/3] [VirtRegMap] Replace a single value enum with a static
 constexpr member variable. NFC

Drop the 'l' suffix on the 1. I guess the old enum had 'long' type?

I'm a bit puzzled why it is using a shift of 30. A long time ago when it was
first created, the value was INT_MAX. Then it was changed in
e2b77d57c0c13 to (~0 >> 1) which I guess was trying to be INT_MAX
without using the constant. But ~0 is an `int` so that produced -1.

I'm not sure what the 'l' suffix was for. Unless that was an attempt
to avoid undefined behavior had the shift been 31 instead of 30. But
'long' is 32 bits on some targets so that wouldn't work.

Maybe we can go back to INT_MAX?
---
 llvm/include/llvm/CodeGen/VirtRegMap.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/VirtRegMap.h b/llvm/include/llvm/CodeGen/VirtRegMap.h
index dee462255b0b28..bdbba03a5fb913 100644
--- a/llvm/include/llvm/CodeGen/VirtRegMap.h
+++ b/llvm/include/llvm/CodeGen/VirtRegMap.h
@@ -32,9 +32,7 @@ class TargetInstrInfo;
 
   class VirtRegMap : public MachineFunctionPass {
   public:
-    enum {
-      NO_STACK_SLOT = (1L << 30)-1,
-    };
+    static constexpr unsigned NO_STACK_SLOT = (1u << 30) - 1;
 
   private:
     MachineRegisterInfo *MRI = nullptr;

>From 628681e58c5711d4a882c226dcd2000cfa140c9c Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 17 Sep 2024 09:49:47 -0700
Subject: [PATCH 2/3] fixup! Use 'int'

---
 llvm/include/llvm/CodeGen/VirtRegMap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/CodeGen/VirtRegMap.h b/llvm/include/llvm/CodeGen/VirtRegMap.h
index bdbba03a5fb913..c6d3fa6862cec4 100644
--- a/llvm/include/llvm/CodeGen/VirtRegMap.h
+++ b/llvm/include/llvm/CodeGen/VirtRegMap.h
@@ -32,7 +32,7 @@ class TargetInstrInfo;
 
   class VirtRegMap : public MachineFunctionPass {
   public:
-    static constexpr unsigned NO_STACK_SLOT = (1u << 30) - 1;
+    static constexpr int NO_STACK_SLOT = (1u << 30) - 1;
 
   private:
     MachineRegisterInfo *MRI = nullptr;

>From 932075ce092e96dc5aa40afd35c011799aadc9f1 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 17 Sep 2024 09:52:05 -0700
Subject: [PATCH 3/3] fixup! combine public sections.

---
 llvm/include/llvm/CodeGen/VirtRegMap.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/VirtRegMap.h b/llvm/include/llvm/CodeGen/VirtRegMap.h
index c6d3fa6862cec4..fbd26e7da768eb 100644
--- a/llvm/include/llvm/CodeGen/VirtRegMap.h
+++ b/llvm/include/llvm/CodeGen/VirtRegMap.h
@@ -31,10 +31,6 @@ class raw_ostream;
 class TargetInstrInfo;
 
   class VirtRegMap : public MachineFunctionPass {
-  public:
-    static constexpr int NO_STACK_SLOT = (1u << 30) - 1;
-
-  private:
     MachineRegisterInfo *MRI = nullptr;
     const TargetInstrInfo *TII = nullptr;
     const TargetRegisterInfo *TRI = nullptr;
@@ -67,6 +63,8 @@ class TargetInstrInfo;
   public:
     static char ID;
 
+    static constexpr int NO_STACK_SLOT = (1u << 30) - 1;
+
     VirtRegMap() : MachineFunctionPass(ID), Virt2StackSlotMap(NO_STACK_SLOT) {}
     VirtRegMap(const VirtRegMap &) = delete;
     VirtRegMap &operator=(const VirtRegMap &) = delete;



More information about the llvm-commits mailing list