-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[TableGen] Print a warning when a Processor contains duplicate Features / TuneFeatures #137864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TableGen] Print a warning when a Processor contains duplicate Features / TuneFeatures #137864
Conversation
…es / TuneFeatures
@llvm/pr-subscribers-tablegen Author: Min-Yih Hsu (mshockwave) ChangesI don't think a processor should normally contains duplicate features. I'm open to make this an error rather than a warning. Full diff: https://github.com/llvm/llvm-project/pull/137864.diff 2 Files Affected:
diff --git a/llvm/test/TableGen/DuplicateProcessorFeatures.td b/llvm/test/TableGen/DuplicateProcessorFeatures.td
new file mode 100644
index 0000000000000..324a70f2a9d9e
--- /dev/null
+++ b/llvm/test/TableGen/DuplicateProcessorFeatures.td
@@ -0,0 +1,16 @@
+// RUN: llvm-tblgen -gen-subtarget -I %p/../../include %s 2>&1 | FileCheck %s
+
+include "llvm/Target/Target.td"
+
+def MyTarget : Target;
+
+def FeatureA : SubtargetFeature<"NameA", "", "", "">;
+def FeatureB : SubtargetFeature<"NameB", "", "", "">;
+def FeatureC : SubtargetFeature<"NameC", "", "", "">;
+
+// CHECK: warning: Processor CPU0 has duplicate Features: NameA
+def P0 : ProcessorModel<"CPU0", NoSchedModel, [FeatureA, FeatureB, FeatureA]>;
+// CHECK: warning: Processor CPU1 has duplicate TuneFeatures: NameB
+def P1 : ProcessorModel<"CPU1", NoSchedModel,
+ /*Features=*/[FeatureA, FeatureB, FeatureC],
+ /*TuneFeatures=*/[FeatureB, FeatureC, FeatureB]>;
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 8d2fc99f84670..c608e85cddffa 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -333,6 +333,16 @@ unsigned SubtargetEmitter::cpuNames(raw_ostream &OS) {
return Names.size();
}
+static void checkDuplicateCPUFeatures(StringRef CPUName, StringRef FeatureKind,
+ ConstRecVec Features) {
+ SmallPtrSet<const Record *, 8> FeatureSet;
+ for (const auto *FeatureRec : Features) {
+ if (!FeatureSet.insert(FeatureRec).second)
+ PrintWarning("Processor " + CPUName + " has duplicate " + FeatureKind +
+ ": " + FeatureRec->getValueAsString("Name"));
+ }
+}
+
//
// CPUKeyValues - Emit data of all the subtarget processors. Used by command
// line.
@@ -357,8 +367,10 @@ unsigned SubtargetEmitter::cpuKeyValues(raw_ostream &OS,
for (const Record *Processor : ProcessorList) {
StringRef Name = Processor->getValueAsString("Name");
ConstRecVec FeatureList = Processor->getValueAsListOfDefs("Features");
+ checkDuplicateCPUFeatures(Name, "Features", FeatureList);
ConstRecVec TuneFeatureList =
Processor->getValueAsListOfDefs("TuneFeatures");
+ checkDuplicateCPUFeatures(Name, "TuneFeatures", TuneFeatureList);
// Emit as "{ "cpu", "description", 0, { f1 , f2 , ... fn } },".
OS << " { "
|
PrintWarning("Processor " + CPUName + | ||
" contains duplicate tune feature '" + | ||
TuneFeatureRec->getValueAsString("Name") + "'"); | ||
if (FeatureSet.count(TuneFeatureRec)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: FeatureSet.contains() for a more canonical form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
LGTM with a small nit. |
static void checkDuplicateCPUFeatures(StringRef CPUName, | ||
ArrayRef<const Record *> Features, | ||
ArrayRef<const Record *> TuneFeatures) { | ||
// We had made sure each SubtargetFeature Record has a unique name, so we can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had->have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/92/builds/17955 Here is the relevant piece of the build log for the reference
|
This is printing new warnings when I build
|
Pending #137903 |
I also see: [2704/5914] Building CSKYGenSubtargetInfo.inc... |
thanks for catching that. PR: #138316 |
…es / TuneFeatures (llvm#137864) I don't think a processor should normally contains duplicate features. This patch prints a warning whenever that happens in either the features or tune features.
…es / TuneFeatures (llvm#137864) I don't think a processor should normally contains duplicate features. This patch prints a warning whenever that happens in either the features or tune features.
…es / TuneFeatures (llvm#137864) I don't think a processor should normally contains duplicate features. This patch prints a warning whenever that happens in either the features or tune features.
…es / TuneFeatures (llvm#137864) I don't think a processor should normally contains duplicate features. This patch prints a warning whenever that happens in either the features or tune features.
…es / TuneFeatures (llvm#137864) I don't think a processor should normally contains duplicate features. This patch prints a warning whenever that happens in either the features or tune features.
I don't think a processor should normally contains duplicate features. I'm open to make this an error rather than a warning.