[llvm] [Tablegen][NFC] Add a check for duplicate features (PR #94223)
Tomas Matheson via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 3 07:03:33 PDT 2024
https://github.com/tmatheson-arm updated https://github.com/llvm/llvm-project/pull/94223
>From ddaf86776b79e7ecace5c61c2357c7e526c70967 Mon Sep 17 00:00:00 2001
From: Tomas Matheson <tomas.matheson at arm.com>
Date: Mon, 3 Jun 2024 14:37:04 +0100
Subject: [PATCH 1/2] [Tablegen][NFC] Add a check for duplicate features
We hit this downstream and the only evidence of the mistake was that
the results of Find on SubtargetFeatureKV were corrupted.
---
llvm/utils/TableGen/SubtargetEmitter.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 323470940fec5..1b8893caa3f7d 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -32,6 +32,7 @@
#include <cstdint>
#include <iterator>
#include <map>
+#include <set>
#include <string>
#include <vector>
@@ -255,6 +256,9 @@ unsigned SubtargetEmitter::FeatureKeyValues(
llvm::sort(FeatureList, LessRecordFieldName());
+ // Check that there are no duplicate keys
+ std::set<StringRef> UniqueKeys;
+
// Begin feature table
OS << "// Sorted (by key) array of values for CPU features.\n"
<< "extern const llvm::SubtargetFeatureKV " << Target
@@ -283,6 +287,9 @@ unsigned SubtargetEmitter::FeatureKeyValues(
OS << " },\n";
++NumFeatures;
+
+ if (!UniqueKeys.insert(CommandLineName).second)
+ PrintFatalError("Duplicate key in SubtargetFeatureKV: " +)
}
// End feature table
>From ea72d39e10ea751f35e3407c144899d76b0471db Mon Sep 17 00:00:00 2001
From: Tomas Matheson <tomas.matheson at arm.com>
Date: Mon, 3 Jun 2024 15:03:16 +0100
Subject: [PATCH 2/2] ...the rest of the patch
---
llvm/utils/TableGen/SubtargetEmitter.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 1b8893caa3f7d..60a0402103ce0 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -289,7 +289,8 @@ unsigned SubtargetEmitter::FeatureKeyValues(
++NumFeatures;
if (!UniqueKeys.insert(CommandLineName).second)
- PrintFatalError("Duplicate key in SubtargetFeatureKV: " +)
+ PrintFatalError("Duplicate key in SubtargetFeatureKV: " +
+ CommandLineName);
}
// End feature table
More information about the llvm-commits
mailing list