https://github.com/adams381 created 
https://github.com/llvm/llvm-project/pull/216339

CIR CallConvLowering keeps one classifier per AVX level, so it sizes an array 
by the number of levels.  It got that number as the current end of the list 
plus one, which stops being the count the moment a level is added after the 
current end.  A runtime assert was necessary to guard the index.

The enum now ends in `NumberOfEnumEntries`, so the count follows the 
enumerators and every level is a valid index by construction.  The assert is no 
longer needed as we know we have the precise count.  Adding a level fails the 
build at `getNativeVectorSizeForAVXABI` until it gets a native vector size, 
which is where that decision belongs.

Review feedback on #215118, deferred to a follow-up.

Assisted-by: Cursor / claude-opus-5


>From d03e9b57037c60fe33abe61623e50a546542f124 Mon Sep 17 00:00:00 2001
From: Adam Smith <[email protected]>
Date: Fri, 14 Aug 2026 08:22:20 -0700
Subject: [PATCH] [ABI][CIR][NFC] Let X86AVXABILevel carry its own count

CIR CallConvLowering keeps one classifier per AVX level, so it sizes an
array by the number of levels.  It got that number as the current end of
the list plus one, which stops being the count the moment a level is
added after the current end.  A runtime assert was necessary to guard
the index.

The enum now ends in NumberOfEnumEntries, so the count follows the
enumerators and every level is a valid index by construction.  The
assert is no longer needed as we know we have the precise count.
Adding a level fails the build at getNativeVectorSizeForAVXABI until it
gets a native vector size, which is where that decision belongs.

Review feedback on #215118, deferred to a follow-up.

Assisted-by: Cursor / claude-opus-5
---
 clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp | 4 +---
 llvm/include/llvm/ABI/TargetInfo.h                        | 1 +
 llvm/lib/ABI/Targets/X86.cpp                              | 2 ++
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp 
b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
index abbe03bde077f..abbb3d9703b71 100644
--- a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
@@ -705,7 +705,7 @@ void CallConvLoweringPass::runOnOperation() {
   // A per-function target attribute can raise the AVX level, so one classifier
   // per module would misclassify a wide vector in such a function.
   static constexpr unsigned numAvxLevels =
-      static_cast<unsigned>(llvm::abi::X86AVXABILevel::AVX512) + 1;
+      static_cast<unsigned>(llvm::abi::X86AVXABILevel::NumberOfEnumEntries);
   bool isX86 = target == cir::CallConvTarget::X86_64;
   std::optional<mlir::abi::ABITypeMapper> x86TypeMapper;
   std::array<std::unique_ptr<llvm::abi::TargetInfo>, numAvxLevels> x86Targets;
@@ -713,8 +713,6 @@ void CallConvLoweringPass::runOnOperation() {
     x86TypeMapper.emplace(dl);
   auto x86TargetFor =
       [&](llvm::abi::X86AVXABILevel level) -> const llvm::abi::TargetInfo & {
-    assert(static_cast<unsigned>(level) < numAvxLevels &&
-           "a new X86AVXABILevel needs a slot in x86Targets");
     std::unique_ptr<llvm::abi::TargetInfo> &slot =
         x86Targets[static_cast<unsigned>(level)];
     if (!slot)
diff --git a/llvm/include/llvm/ABI/TargetInfo.h 
b/llvm/include/llvm/ABI/TargetInfo.h
index 7d57893da0cf5..b7be8c24349bc 100644
--- a/llvm/include/llvm/ABI/TargetInfo.h
+++ b/llvm/include/llvm/ABI/TargetInfo.h
@@ -91,6 +91,7 @@ enum class X86AVXABILevel {
   None,
   AVX,
   AVX512,
+  NumberOfEnumEntries // must be last
 };
 
 LLVM_ABI std::unique_ptr<TargetInfo>
diff --git a/llvm/lib/ABI/Targets/X86.cpp b/llvm/lib/ABI/Targets/X86.cpp
index 83c13f0071f23..f372bcd511009 100644
--- a/llvm/lib/ABI/Targets/X86.cpp
+++ b/llvm/lib/ABI/Targets/X86.cpp
@@ -29,6 +29,8 @@ static unsigned getNativeVectorSizeForAVXABI(X86AVXABILevel 
AVXLevel) {
     return 256;
   case X86AVXABILevel::None:
     return 128;
+  case X86AVXABILevel::NumberOfEnumEntries:
+    break;
   }
   llvm_unreachable("Unknown AVXLevel");
 }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to