Skip to content

[TableGen] Check for duplicate register tuple definitions. #95725

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

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions llvm/test/TableGen/check-duplicate-tuple-regs.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: not llvm-tblgen -gen-register-info -I %p/../../include -I %p/Common %s 2>&1 | FileCheck %s

include "reg-with-subregs-common.td"

// CHECK: error: Register tuple redefines register 'R0_R1_R2_R3'
def GPR128_Aligned : RegisterTuples<[sub0, sub1, sub2, sub3],
[(decimate (shl GPR32, 0), 4),
(decimate (shl GPR32, 1), 4),
(decimate (shl GPR32, 2), 4),
(decimate (shl GPR32, 3), 4)]>;
10 changes: 10 additions & 0 deletions llvm/utils/TableGen/Common/CodeGenRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -618,6 +619,9 @@ struct TupleExpander : SetTheory::Expander {
// the synthesized definitions for their lifetime.
std::vector<std::unique_ptr<Record>> &SynthDefs;

// Track all synthesized tuple names in order to detect duplicate definitions.
llvm::StringSet<> TupleNames;

TupleExpander(std::vector<std::unique_ptr<Record>> &SynthDefs)
: SynthDefs(SynthDefs) {}

Expand Down Expand Up @@ -684,6 +688,12 @@ struct TupleExpander : SetTheory::Expander {
Record *NewReg = SynthDefs.back().get();
Elts.insert(NewReg);

// Detect duplicates among synthesized registers.
const auto Res = TupleNames.insert(NewReg->getName());
if (!Res.second)
PrintFatalError(Def->getLoc(),
"Register tuple redefines register '" + Name + "'.");

// Copy Proto super-classes.
ArrayRef<std::pair<Record *, SMRange>> Supers = Proto->getSuperClasses();
for (const auto &SuperPair : Supers)
Expand Down
Loading