[llvm] [Support] Remove the now-unused EnumEntry (PR #206330)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 28 06:13:07 PDT 2026


https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/206330

None

>From 9a9b05ad69e225673c291ae0644bb1af836de2db Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Sun, 28 Jun 2026 13:12:28 +0000
Subject: [PATCH] [spr] initial version

Created using spr 1.3.8-wip
---
 llvm/include/llvm/Support/ScopedPrinter.h    |  82 -----
 llvm/unittests/Support/ScopedPrinterTest.cpp | 307 -------------------
 2 files changed, 389 deletions(-)

diff --git a/llvm/include/llvm/Support/ScopedPrinter.h b/llvm/include/llvm/Support/ScopedPrinter.h
index a0cf8ed7f32fd..f6fd2671e812f 100644
--- a/llvm/include/llvm/Support/ScopedPrinter.h
+++ b/llvm/include/llvm/Support/ScopedPrinter.h
@@ -25,22 +25,6 @@
 
 namespace llvm {
 
-template <typename T> struct EnumEntry {
-  StringRef Name;
-  // While Name suffices in most of the cases, in certain cases
-  // GNU style and LLVM style of ELFDumper do not
-  // display same string for same enum. The AltName if initialized appropriately
-  // will hold the string that GNU style emits.
-  // Example:
-  // "EM_X86_64" string on LLVM style for Elf_Ehdr->e_machine corresponds to
-  // "Advanced Micro Devices X86-64" on GNU style
-  StringRef AltName;
-  T Value;
-  constexpr EnumEntry(StringRef N, StringRef A, T V)
-      : Name(N), AltName(A), Value(V) {}
-  constexpr EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
-};
-
 struct HexNumber {
   // To avoid sign-extension we have to explicitly cast to the appropriate
   // unsigned type. The overloads are here so that every type that is implicitly
@@ -100,25 +84,6 @@ template <class T> std::string to_string(const T &Value) {
   return number;
 }
 
-template <typename T, typename TEnum>
-std::string enumToString(T Value, ArrayRef<EnumEntry<TEnum>> EnumValues) {
-  for (const EnumEntry<TEnum> &EnumItem : EnumValues)
-    if (EnumItem.Value == Value)
-      return std::string(EnumItem.AltName);
-  return utohexstr(Value, true);
-}
-
-/// Retrieves the Value's enum name.
-///
-/// Returns an empty StringRef when an invalid value is provided.
-template <typename T, typename TEnum>
-StringRef enumToStringRef(T Value, ArrayRef<EnumEntry<TEnum>> EnumValues) {
-  for (const EnumEntry<TEnum> &EnumItem : EnumValues)
-    if (EnumItem.Value == Value)
-      return EnumItem.AltName;
-  return "";
-}
-
 class LLVM_ABI ScopedPrinter {
 public:
   enum class ScopedPrinterKind {
@@ -169,25 +134,6 @@ class LLVM_ABI ScopedPrinter {
       printHex(Label, Value);
   }
 
-  template <typename T, typename TEnum>
-  void printEnum(StringRef Label, T Value,
-                 ArrayRef<EnumEntry<TEnum>> EnumValues) {
-    StringRef Name;
-    bool Found = false;
-    for (const auto &EnumItem : EnumValues) {
-      if (EnumItem.Value == Value) {
-        Name = EnumItem.Name;
-        Found = true;
-        break;
-      }
-    }
-
-    if (Found)
-      printHex(Label, Name, Value);
-    else
-      printHex(Label, Value);
-  }
-
   template <typename T, typename TFlag, unsigned NumStrs>
   void printFlags(StringRef Label, T Value, EnumStrings<TFlag, NumStrs> Flags,
                   TFlag EnumMask1 = {}, TFlag EnumMask2 = {},
@@ -216,34 +162,6 @@ class LLVM_ABI ScopedPrinter {
     printFlagsImpl(Label, hex(Value), SetFlags);
   }
 
-  template <typename T, typename TFlag>
-  void printFlags(StringRef Label, T Value, ArrayRef<EnumEntry<TFlag>> Flags,
-                  TFlag EnumMask1 = {}, TFlag EnumMask2 = {},
-                  TFlag EnumMask3 = {}, ArrayRef<FlagEntry> ExtraFlags = {}) {
-    SmallVector<FlagEntry, 10> SetFlags(ExtraFlags);
-
-    for (const auto &Flag : Flags) {
-      if (Flag.Value == TFlag{})
-        continue;
-
-      TFlag EnumMask{};
-      if ((Flag.Value & EnumMask1) != TFlag{})
-        EnumMask = EnumMask1;
-      else if ((Flag.Value & EnumMask2) != TFlag{})
-        EnumMask = EnumMask2;
-      else if ((Flag.Value & EnumMask3) != TFlag{})
-        EnumMask = EnumMask3;
-      bool IsEnum = (Flag.Value & EnumMask) != TFlag{};
-      if ((!IsEnum && (Value & Flag.Value) == Flag.Value) ||
-          (IsEnum && (Value & EnumMask) == Flag.Value)) {
-        SetFlags.emplace_back(Flag.Name, Flag.Value);
-      }
-    }
-
-    llvm::sort(SetFlags, &flagName);
-    printFlagsImpl(Label, hex(Value), SetFlags);
-  }
-
   template <typename T>
   void printFlags(StringRef Label, T Value,
                   SmallVectorImpl<FlagEntry> &SetFlags) {
diff --git a/llvm/unittests/Support/ScopedPrinterTest.cpp b/llvm/unittests/Support/ScopedPrinterTest.cpp
index 366e5b44231cc..d2b0d643a0be9 100644
--- a/llvm/unittests/Support/ScopedPrinterTest.cpp
+++ b/llvm/unittests/Support/ScopedPrinterTest.cpp
@@ -551,313 +551,6 @@ BitmaskEnum::F1 [ (0x1)
   verifyAll(ExpectedOut, JSONExpectedOut, PrintFunc);
 }
 
-TEST_F(ScopedPrinterTest, PrintEnum) {
-  auto PrintFunc = [](ScopedPrinter &W) {
-    const EnumEntry<int> EnumList[] = {{"Name1", "AltName1", 1},
-                                       {"Name2", "AltName2", 2},
-                                       {"Name3", "AltName3", 3},
-                                       {"Name4", "AltName4", 2}};
-    EnumEntry<int> OtherEnum{"Name5", "AltName5", 5};
-    W.printEnum("Exists", EnumList[1].Value, ArrayRef(EnumList));
-    W.printEnum("DoesNotExist", OtherEnum.Value, ArrayRef(EnumList));
-  };
-
-  const char *ExpectedOut = R"(Exists: Name2 (0x2)
-DoesNotExist: 0x5
-)";
-
-  const char *JSONExpectedOut = R"({
-  "Exists": {
-    "Name": "Name2",
-    "Value": 2
-  },
-  "DoesNotExist": 5
-})";
-  verifyAll(ExpectedOut, JSONExpectedOut, PrintFunc);
-}
-
-TEST_F(ScopedPrinterTest, PrintFlag) {
-  auto PrintFunc = [](ScopedPrinter &W) {
-    const EnumEntry<uint16_t> SingleBitFlags[] = {
-        {"Name0", "AltName0", 0},
-        {"Name1", "AltName1", 1},
-        {"Name2", "AltName2", 1 << 1},
-        {"Name3", "AltName3", 1 << 2}};
-    const EnumEntry<uint16_t> UnsortedFlags[] = {
-        {"C", "c", 1}, {"B", "b", 1 << 1}, {"A", "a", 1 << 2}};
-    const EnumEntry<uint16_t> EnumFlags[] = {
-        {"FirstByte1", "First1", 0x1u},    {"FirstByte2", "First2", 0x2u},
-        {"FirstByte3", "First3", 0x3u},    {"SecondByte1", "Second1", 0x10u},
-        {"SecondByte2", "Second2", 0x20u}, {"SecondByte3", "Second3", 0x30u},
-        {"ThirdByte1", "Third1", 0x100u},  {"ThirdByte2", "Third2", 0x200u},
-        {"ThirdByte3", "Third3", 0x300u}};
-
-    const EnumEntry<BitmaskEnum> ScopedFlags[] = {
-        {"F1", "AltF1", BitmaskEnum::F1},
-        {"F2", "AltF2", BitmaskEnum::F2},
-    };
-
-    W.printFlags("ZeroFlag", 0, ArrayRef(SingleBitFlags));
-    W.printFlags("NoFlag", 1 << 3, ArrayRef(SingleBitFlags));
-    W.printFlags("Flag1", SingleBitFlags[1].Value, ArrayRef(SingleBitFlags));
-    W.printFlags("Flag1&3", (1 << 2) + 1, ArrayRef(SingleBitFlags));
-
-    W.printFlags("ZeroFlagRaw", 0);
-    W.printFlags("NoFlagRaw", 1 << 3);
-    W.printFlags("Flag1Raw", SingleBitFlags[1].Value);
-    W.printFlags("Flag1&3Raw", (1 << 2) + 1);
-
-    W.printFlags("FlagSorted", (1 << 2) + (1 << 1) + 1,
-                 ArrayRef(UnsortedFlags));
-
-    uint16_t NoBitMask = 0;
-    uint16_t FirstByteMask = 0xFu;
-    uint16_t SecondByteMask = 0xF0u;
-    uint16_t ThirdByteMask = 0xF00u;
-    W.printFlags("NoBitMask", 0xFFFu, ArrayRef(EnumFlags), NoBitMask);
-    W.printFlags("FirstByteMask", 0x3u, ArrayRef(EnumFlags), FirstByteMask);
-    W.printFlags("SecondByteMask", 0x30u, ArrayRef(EnumFlags), SecondByteMask);
-    W.printFlags("ValueOutsideMask", 0x1u, ArrayRef(EnumFlags), SecondByteMask);
-    W.printFlags("FirstSecondByteMask", 0xFFu, ArrayRef(EnumFlags),
-                 FirstByteMask, SecondByteMask);
-    W.printFlags("FirstSecondThirdByteMask", 0x333u, ArrayRef(EnumFlags),
-                 FirstByteMask, SecondByteMask, ThirdByteMask);
-    W.printFlags("BitmaskEnum::F1", BitmaskEnum::F1, ArrayRef(ScopedFlags));
-  };
-
-  const char *ExpectedOut = R"(ZeroFlag [ (0x0)
-]
-NoFlag [ (0x8)
-]
-Flag1 [ (0x1)
-  Name1 (0x1)
-]
-Flag1&3 [ (0x5)
-  Name1 (0x1)
-  Name3 (0x4)
-]
-ZeroFlagRaw [ (0x0)
-]
-NoFlagRaw [ (0x8)
-  0x8
-]
-Flag1Raw [ (0x1)
-  0x1
-]
-Flag1&3Raw [ (0x5)
-  0x1
-  0x4
-]
-FlagSorted [ (0x7)
-  A (0x4)
-  B (0x2)
-  C (0x1)
-]
-NoBitMask [ (0xFFF)
-  FirstByte1 (0x1)
-  FirstByte2 (0x2)
-  FirstByte3 (0x3)
-  SecondByte1 (0x10)
-  SecondByte2 (0x20)
-  SecondByte3 (0x30)
-  ThirdByte1 (0x100)
-  ThirdByte2 (0x200)
-  ThirdByte3 (0x300)
-]
-FirstByteMask [ (0x3)
-  FirstByte3 (0x3)
-]
-SecondByteMask [ (0x30)
-  SecondByte3 (0x30)
-]
-ValueOutsideMask [ (0x1)
-  FirstByte1 (0x1)
-]
-FirstSecondByteMask [ (0xFF)
-]
-FirstSecondThirdByteMask [ (0x333)
-  FirstByte3 (0x3)
-  SecondByte3 (0x30)
-  ThirdByte3 (0x300)
-]
-BitmaskEnum::F1 [ (0x1)
-  F1 (0x1)
-]
-)";
-
-  const char *JSONExpectedOut = R"({
-  "ZeroFlag": {
-    "Value": 0,
-    "Flags": []
-  },
-  "NoFlag": {
-    "Value": 8,
-    "Flags": []
-  },
-  "Flag1": {
-    "Value": 1,
-    "Flags": [
-      {
-        "Name": "Name1",
-        "Value": 1
-      }
-    ]
-  },
-  "Flag1&3": {
-    "Value": 5,
-    "Flags": [
-      {
-        "Name": "Name1",
-        "Value": 1
-      },
-      {
-        "Name": "Name3",
-        "Value": 4
-      }
-    ]
-  },
-  "ZeroFlagRaw": {
-    "Value": 0,
-    "Flags": []
-  },
-  "NoFlagRaw": {
-    "Value": 8,
-    "Flags": [
-      8
-    ]
-  },
-  "Flag1Raw": {
-    "Value": 1,
-    "Flags": [
-      1
-    ]
-  },
-  "Flag1&3Raw": {
-    "Value": 5,
-    "Flags": [
-      1,
-      4
-    ]
-  },
-  "FlagSorted": {
-    "Value": 7,
-    "Flags": [
-      {
-        "Name": "A",
-        "Value": 4
-      },
-      {
-        "Name": "B",
-        "Value": 2
-      },
-      {
-        "Name": "C",
-        "Value": 1
-      }
-    ]
-  },
-  "NoBitMask": {
-    "Value": 4095,
-    "Flags": [
-      {
-        "Name": "FirstByte1",
-        "Value": 1
-      },
-      {
-        "Name": "FirstByte2",
-        "Value": 2
-      },
-      {
-        "Name": "FirstByte3",
-        "Value": 3
-      },
-      {
-        "Name": "SecondByte1",
-        "Value": 16
-      },
-      {
-        "Name": "SecondByte2",
-        "Value": 32
-      },
-      {
-        "Name": "SecondByte3",
-        "Value": 48
-      },
-      {
-        "Name": "ThirdByte1",
-        "Value": 256
-      },
-      {
-        "Name": "ThirdByte2",
-        "Value": 512
-      },
-      {
-        "Name": "ThirdByte3",
-        "Value": 768
-      }
-    ]
-  },
-  "FirstByteMask": {
-    "Value": 3,
-    "Flags": [
-      {
-        "Name": "FirstByte3",
-        "Value": 3
-      }
-    ]
-  },
-  "SecondByteMask": {
-    "Value": 48,
-    "Flags": [
-      {
-        "Name": "SecondByte3",
-        "Value": 48
-      }
-    ]
-  },
-  "ValueOutsideMask": {
-    "Value": 1,
-    "Flags": [
-      {
-        "Name": "FirstByte1",
-        "Value": 1
-      }
-    ]
-  },
-  "FirstSecondByteMask": {
-    "Value": 255,
-    "Flags": []
-  },
-  "FirstSecondThirdByteMask": {
-    "Value": 819,
-    "Flags": [
-      {
-        "Name": "FirstByte3",
-        "Value": 3
-      },
-      {
-        "Name": "SecondByte3",
-        "Value": 48
-      },
-      {
-        "Name": "ThirdByte3",
-        "Value": 768
-      }
-    ]
-  },
-  "BitmaskEnum::F1": {
-    "Value": 1,
-    "Flags": [
-      {
-        "Name": "F1",
-        "Value": 1
-      }
-    ]
-  }
-})";
-  verifyAll(ExpectedOut, JSONExpectedOut, PrintFunc);
-}
-
 // Format floats using the same format string as PrintNumber, so we can check
 // the output on all platforms.
 template <typename T,



More information about the llvm-commits mailing list