Skip to content

Commit a4b1617

Browse files
authored
[clang][TableGen] Change NeonEmitter to use const RecordKeeper (#108501)
Change NeonEmitter to use const RecordKeeper. This is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
1 parent 75d8724 commit a4b1617

File tree

2 files changed

+34
-39
lines changed

2 files changed

+34
-39
lines changed

clang/utils/TableGen/NeonEmitter.cpp

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace {
5959
// While globals are generally bad, this one allows us to perform assertions
6060
// liberally and somehow still trace them back to the def they indirectly
6161
// came from.
62-
static Record *CurrentRecord = nullptr;
62+
static const Record *CurrentRecord = nullptr;
6363
static void assert_with_loc(bool Assertion, const std::string &Str) {
6464
if (!Assertion) {
6565
if (CurrentRecord)
@@ -308,7 +308,7 @@ class Variable {
308308
/// a particular typespec and prototype.
309309
class Intrinsic {
310310
/// The Record this intrinsic was created from.
311-
Record *R;
311+
const Record *R;
312312
/// The unmangled name.
313313
std::string Name;
314314
/// The input and output typespecs. InTS == OutTS except when
@@ -371,7 +371,7 @@ class Intrinsic {
371371
}
372372

373373
public:
374-
Intrinsic(Record *R, StringRef Name, StringRef Proto, TypeSpec OutTS,
374+
Intrinsic(const Record *R, StringRef Name, StringRef Proto, TypeSpec OutTS,
375375
TypeSpec InTS, ClassKind CK, ListInit *Body, NeonEmitter &Emitter,
376376
StringRef ArchGuard, StringRef TargetGuard, bool IsUnavailable,
377377
bool BigEndianSafe)
@@ -442,7 +442,7 @@ class Intrinsic {
442442
}
443443

444444
/// Get the Record that this intrinsic is based off.
445-
Record *getRecord() const { return R; }
445+
const Record *getRecord() const { return R; }
446446
/// Get the set of Intrinsics that this intrinsic calls.
447447
/// this is the set of immediate dependencies, NOT the
448448
/// transitive closure.
@@ -576,12 +576,12 @@ class Intrinsic {
576576
//===----------------------------------------------------------------------===//
577577

578578
class NeonEmitter {
579-
RecordKeeper &Records;
580-
DenseMap<Record *, ClassKind> ClassMap;
579+
const RecordKeeper &Records;
580+
DenseMap<const Record *, ClassKind> ClassMap;
581581
std::map<std::string, std::deque<Intrinsic>> IntrinsicMap;
582582
unsigned UniqueNumber;
583583

584-
void createIntrinsic(Record *R, SmallVectorImpl<Intrinsic *> &Out);
584+
void createIntrinsic(const Record *R, SmallVectorImpl<Intrinsic *> &Out);
585585
void genBuiltinsDef(raw_ostream &OS, SmallVectorImpl<Intrinsic *> &Defs);
586586
void genStreamingSVECompatibleList(raw_ostream &OS,
587587
SmallVectorImpl<Intrinsic *> &Defs);
@@ -601,15 +601,15 @@ class NeonEmitter {
601601
/// Called by Intrinsic - returns a globally-unique number.
602602
unsigned getUniqueNumber() { return UniqueNumber++; }
603603

604-
NeonEmitter(RecordKeeper &R) : Records(R), UniqueNumber(0) {
605-
Record *SI = R.getClass("SInst");
606-
Record *II = R.getClass("IInst");
607-
Record *WI = R.getClass("WInst");
608-
Record *SOpI = R.getClass("SOpInst");
609-
Record *IOpI = R.getClass("IOpInst");
610-
Record *WOpI = R.getClass("WOpInst");
611-
Record *LOpI = R.getClass("LOpInst");
612-
Record *NoTestOpI = R.getClass("NoTestOpInst");
604+
NeonEmitter(const RecordKeeper &R) : Records(R), UniqueNumber(0) {
605+
const Record *SI = R.getClass("SInst");
606+
const Record *II = R.getClass("IInst");
607+
const Record *WI = R.getClass("WInst");
608+
const Record *SOpI = R.getClass("SOpInst");
609+
const Record *IOpI = R.getClass("IOpInst");
610+
const Record *WOpI = R.getClass("WOpInst");
611+
const Record *LOpI = R.getClass("LOpInst");
612+
const Record *NoTestOpI = R.getClass("NoTestOpInst");
613613

614614
ClassMap[SI] = ClassS;
615615
ClassMap[II] = ClassI;
@@ -1979,12 +1979,12 @@ Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types,
19791979
return *GoodVec.front();
19801980
}
19811981

1982-
void NeonEmitter::createIntrinsic(Record *R,
1982+
void NeonEmitter::createIntrinsic(const Record *R,
19831983
SmallVectorImpl<Intrinsic *> &Out) {
19841984
std::string Name = std::string(R->getValueAsString("Name"));
19851985
std::string Proto = std::string(R->getValueAsString("Prototype"));
19861986
std::string Types = std::string(R->getValueAsString("Types"));
1987-
Record *OperationRec = R->getValueAsDef("Operation");
1987+
const Record *OperationRec = R->getValueAsDef("Operation");
19881988
bool BigEndianSafe = R->getValueAsBit("BigEndianSafe");
19891989
std::string ArchGuard = std::string(R->getValueAsString("ArchGuard"));
19901990
std::string TargetGuard = std::string(R->getValueAsString("TargetGuard"));
@@ -2240,10 +2240,8 @@ void NeonEmitter::genIntrinsicRangeCheckCode(
22402240
/// 2. the SemaChecking code for the type overload checking.
22412241
/// 3. the SemaChecking code for validation of intrinsic immediate arguments.
22422242
void NeonEmitter::runHeader(raw_ostream &OS) {
2243-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
2244-
22452243
SmallVector<Intrinsic *, 128> Defs;
2246-
for (auto *R : RV)
2244+
for (const Record *R : Records.getAllDerivedDefinitions("Inst"))
22472245
createIntrinsic(R, Defs);
22482246

22492247
// Generate shared BuiltinsXXX.def
@@ -2402,8 +2400,7 @@ void NeonEmitter::run(raw_ostream &OS) {
24022400
"__nodebug__))\n\n";
24032401

24042402
SmallVector<Intrinsic *, 128> Defs;
2405-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
2406-
for (auto *R : RV)
2403+
for (const Record *R : Records.getAllDerivedDefinitions("Inst"))
24072404
createIntrinsic(R, Defs);
24082405

24092406
for (auto *I : Defs)
@@ -2510,8 +2507,7 @@ void NeonEmitter::runFP16(raw_ostream &OS) {
25102507
"__nodebug__))\n\n";
25112508

25122509
SmallVector<Intrinsic *, 128> Defs;
2513-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
2514-
for (auto *R : RV)
2510+
for (const Record *R : Records.getAllDerivedDefinitions("Inst"))
25152511
createIntrinsic(R, Defs);
25162512

25172513
for (auto *I : Defs)
@@ -2619,8 +2615,7 @@ void NeonEmitter::runBF16(raw_ostream &OS) {
26192615
"__nodebug__))\n\n";
26202616

26212617
SmallVector<Intrinsic *, 128> Defs;
2622-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
2623-
for (auto *R : RV)
2618+
for (const Record *R : Records.getAllDerivedDefinitions("Inst"))
26242619
createIntrinsic(R, Defs);
26252620

26262621
for (auto *I : Defs)
@@ -2674,26 +2669,26 @@ void NeonEmitter::runBF16(raw_ostream &OS) {
26742669
OS << "#endif\n";
26752670
}
26762671

2677-
void clang::EmitNeon(RecordKeeper &Records, raw_ostream &OS) {
2672+
void clang::EmitNeon(const RecordKeeper &Records, raw_ostream &OS) {
26782673
NeonEmitter(Records).run(OS);
26792674
}
26802675

2681-
void clang::EmitFP16(RecordKeeper &Records, raw_ostream &OS) {
2676+
void clang::EmitFP16(const RecordKeeper &Records, raw_ostream &OS) {
26822677
NeonEmitter(Records).runFP16(OS);
26832678
}
26842679

2685-
void clang::EmitBF16(RecordKeeper &Records, raw_ostream &OS) {
2680+
void clang::EmitBF16(const RecordKeeper &Records, raw_ostream &OS) {
26862681
NeonEmitter(Records).runBF16(OS);
26872682
}
26882683

2689-
void clang::EmitNeonSema(RecordKeeper &Records, raw_ostream &OS) {
2684+
void clang::EmitNeonSema(const RecordKeeper &Records, raw_ostream &OS) {
26902685
NeonEmitter(Records).runHeader(OS);
26912686
}
26922687

2693-
void clang::EmitVectorTypes(RecordKeeper &Records, raw_ostream &OS) {
2688+
void clang::EmitVectorTypes(const RecordKeeper &Records, raw_ostream &OS) {
26942689
NeonEmitter(Records).runVectorTypes(OS);
26952690
}
26962691

2697-
void clang::EmitNeonTest(RecordKeeper &Records, raw_ostream &OS) {
2692+
void clang::EmitNeonTest(const RecordKeeper &Records, raw_ostream &OS) {
26982693
llvm_unreachable("Neon test generation no longer implemented!");
26992694
}

clang/utils/TableGen/TableGenBackends.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ void EmitClangSyntaxNodeList(const llvm::RecordKeeper &Records,
115115
void EmitClangSyntaxNodeClasses(const llvm::RecordKeeper &Records,
116116
llvm::raw_ostream &OS);
117117

118-
void EmitNeon(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
119-
void EmitFP16(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
120-
void EmitBF16(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
121-
void EmitNeonSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
122-
void EmitVectorTypes(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
123-
void EmitNeonTest(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
118+
void EmitNeon(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
119+
void EmitFP16(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
120+
void EmitBF16(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
121+
void EmitNeonSema(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
122+
void EmitVectorTypes(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
123+
void EmitNeonTest(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
124124

125125
void EmitImmCheckTypes(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
126126
void EmitSveHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);

0 commit comments

Comments
 (0)