[clang] [llvm] Replace cl::bits with cl::list. NFC (PR #226399)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 01:53:29 PDT 2026


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/226399

cl::bits packs enum values into an unsigned, which would block migration
to TableGen based representation. The three users only test membership.

LLM-aided

>From 5f02d6f0e775bd467617f615e7a75f49f2030985 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Fri, 25 Sep 2026 01:45:37 -0700
Subject: [PATCH] Replace cl::bits with cl::list. NFC

cl::bits packs enum values into an unsigned, which would block migration
to TableGen based representation. The three users only test membership.

LLM-aided
---
 clang/tools/clang-format/ClangFormat.cpp      |  4 +--
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp    | 28 ++++++++-----------
 .../Target/AArch64/AArch64CodeLayoutOpt.cpp   |  6 ++--
 3 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index d465ed57f0033e..743c7c27a9f5d2 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -175,7 +175,7 @@ namespace {
 enum class WNoError { Unknown };
 }
 
-static cl::bits<WNoError> WNoErrorList(
+static cl::list<WNoError> WNoErrorList(
     "Wno-error",
     cl::desc("If set, don't error out on the specified warning type."),
     cl::values(
@@ -443,7 +443,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
 
   Expected<FormatStyle> FormatStyle =
       getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer(),
-               nullptr, WNoErrorList.isSet(WNoError::Unknown));
+               nullptr, is_contained(WNoErrorList, WNoError::Unknown));
   if (!FormatStyle) {
     llvm::errs() << toString(FormatStyle.takeError()) << "\n";
     return true;
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 52f8f148f74877..8c30f91ac08559 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -143,10 +143,6 @@ using namespace llvm;
 
 #define DEBUG_TYPE "asm-printer"
 
-// This is a replication of fields of object::PGOAnalysisMap::Features. It
-// should match the order of the fields so that
-// `object::PGOAnalysisMap::Features::decode(PgoAnalysisMapFeatures.getBits())`
-// succeeds.
 enum class PGOMapFeaturesEnum {
   None,
   FuncEntryCount,
@@ -155,7 +151,7 @@ enum class PGOMapFeaturesEnum {
   PropellerCFG,
   All,
 };
-static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
+static cl::list<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
     "pgo-analysis-map", cl::Hidden, cl::CommaSeparated,
     cl::values(
         clEnumValN(PGOMapFeaturesEnum::None, "none", "Disable all options"),
@@ -1493,25 +1489,23 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
                     bool HasCalls, const CFGProfile *FuncCFGProfile) {
   // Ensure that the user has not passed in additional options while also
   // specifying all or none.
-  if ((PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::None) ||
-       PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::All)) &&
-      popcount(PgoAnalysisMapFeatures.getBits()) != 1) {
+  auto IsSet = [](PGOMapFeaturesEnum F) {
+    return is_contained(PgoAnalysisMapFeatures, F);
+  };
+  bool NoFeatures = IsSet(PGOMapFeaturesEnum::None);
+  bool AllFeatures = IsSet(PGOMapFeaturesEnum::All);
+  if ((NoFeatures || AllFeatures) && !all_equal(PgoAnalysisMapFeatures)) {
     MF.getFunction().getContext().emitError(
         "-pgo-analysis-map can accept only all or none with no additional "
         "values.");
   }
 
-  bool NoFeatures = PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::None);
-  bool AllFeatures = PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::All);
   bool FuncEntryCountEnabled =
-      AllFeatures || (!NoFeatures && PgoAnalysisMapFeatures.isSet(
-                                         PGOMapFeaturesEnum::FuncEntryCount));
+      AllFeatures || (!NoFeatures && IsSet(PGOMapFeaturesEnum::FuncEntryCount));
   bool BBFreqEnabled =
-      AllFeatures ||
-      (!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BBFreq));
+      AllFeatures || (!NoFeatures && IsSet(PGOMapFeaturesEnum::BBFreq));
   bool BrProbEnabled =
-      AllFeatures ||
-      (!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BrProb));
+      AllFeatures || (!NoFeatures && IsSet(PGOMapFeaturesEnum::BrProb));
   bool PostLinkCfgEnabled = FuncCFGProfile && PgoAnalysisMapEmitBBSectionsCfg;
 
   if ((BBFreqEnabled || BrProbEnabled) && BBAddrMapSkipEmitBBEntries) {
@@ -2565,7 +2559,7 @@ void AsmPrinter::emitFunctionBody() {
   if (HasAnyRealCode) {
     if (MF->getTarget().Options.BBAddrMap)
       emitBBAddrMapSection(*MF);
-    else if (PgoAnalysisMapFeatures.getBits() != 0)
+    else if (!PgoAnalysisMapFeatures.empty())
       MF->getContext().reportWarning(
           SMLoc(), "pgo-analysis-map is enabled for function " + MF->getName() +
                        " but it does not have labels");
diff --git a/llvm/lib/Target/AArch64/AArch64CodeLayoutOpt.cpp b/llvm/lib/Target/AArch64/AArch64CodeLayoutOpt.cpp
index f034f21d73dbca..76ba3f38be5497 100644
--- a/llvm/lib/Target/AArch64/AArch64CodeLayoutOpt.cpp
+++ b/llvm/lib/Target/AArch64/AArch64CodeLayoutOpt.cpp
@@ -44,7 +44,7 @@ enum CodeLayoutOpt {
   LLVM_MARK_AS_BITMASK_ENUM(FcmpFcsel)
 };
 
-static cl::bits<CodeLayoutOpt> EnableCodeAlignment(
+static cl::list<CodeLayoutOpt> EnableCodeAlignment(
     "aarch64-code-layout-opt-enable", cl::Hidden, cl::CommaSeparated,
     cl::desc("Enable code alignment optimization for instruction pairs"),
     cl::values(
@@ -180,9 +180,9 @@ bool AArch64CodeLayoutOpt::runOnMachineFunction(MachineFunction &MF) {
 
   CodeLayoutOpt CLO = None;
   if (EnableCodeAlignment.getNumOccurrences()) {
-    if (EnableCodeAlignment.isSet(CodeLayoutOpt::CmpCsel))
+    if (is_contained(EnableCodeAlignment, CodeLayoutOpt::CmpCsel))
       CLO |= CodeLayoutOpt::CmpCsel;
-    if (EnableCodeAlignment.isSet(CodeLayoutOpt::FcmpFcsel))
+    if (is_contained(EnableCodeAlignment, CodeLayoutOpt::FcmpFcsel))
       CLO |= CodeLayoutOpt::FcmpFcsel;
   } else {
     // Default: enable when the subtarget opts in via FeatureAlignCmpCSelPairs.



More information about the llvm-commits mailing list