From 1aeb3314d8d77040527accc44aaf9d3959ac1f20 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 28 Jan 2022 22:37:00 -0800 Subject: [PATCH] [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 --- llvm/utils/TableGen/CodeGenSchedule.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp index 7c1c37f7b370..9548dca84f5f 100644 --- a/llvm/utils/TableGen/CodeGenSchedule.cpp +++ b/llvm/utils/TableGen/CodeGenSchedule.cpp @@ -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);