Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions llvm/test/TableGen/DuplicateProcessorFeatures.td
Original file line number Diff line number Diff line change
@@ -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]>;
12 changes: 12 additions & 0 deletions llvm/utils/TableGen/SubtargetEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 << " { "
Expand Down