[TableGen] Detect multiple Processors with the same name.

Due to a bad merge we ended up with duplicate entries in our
downstream repo. I was surprised that nothing caught it. I wrote
this check so I could fix our downstream repo and figured I might
as well share it.

Reviewed By: RKSimon, spatel

Differential Revision: https://reviews.llvm.org/D118497
This commit is contained in:
Craig Topper 2022-01-28 22:37:00 -08:00
parent 46283589ef
commit 1aeb3314d8
1 changed files with 9 additions and 0 deletions

View File

@ -521,6 +521,15 @@ void CodeGenSchedModels::collectProcModels() {
RecVec ProcRecords = Records.getAllDerivedDefinitions("Processor");
llvm::sort(ProcRecords, LessRecordFieldName());
// Check for duplicated names.
auto I = std::adjacent_find(ProcRecords.begin(), ProcRecords.end(),
[](const Record *Rec1, const Record *Rec2) {
return Rec1->getValueAsString("Name") == Rec2->getValueAsString("Name");
});
if (I != ProcRecords.end())
PrintFatalError((*I)->getLoc(), "Duplicate processor name " +
(*I)->getValueAsString("Name"));
// Reserve space because we can. Reallocation would be ok.
ProcModels.reserve(ProcRecords.size()+1);