Skip to content

Commit 711278e

Browse files
authored
[clang][TableGen] Change SVE Emitter to use const RecordKeeper (#108503)
Change SVE Emitter 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 ab06a18 commit 711278e

File tree

2 files changed

+46
-40
lines changed

2 files changed

+46
-40
lines changed

clang/utils/TableGen/SveEmitter.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ class SVEEmitter {
280280

281281
static const std::array<ReinterpretTypeInfo, 12> Reinterprets;
282282

283-
RecordKeeper &Records;
283+
const RecordKeeper &Records;
284284
llvm::StringMap<uint64_t> EltTypes;
285285
llvm::StringMap<uint64_t> MemEltTypes;
286286
llvm::StringMap<uint64_t> FlagTypes;
287287
llvm::StringMap<uint64_t> MergeTypes;
288288
llvm::StringMap<uint64_t> ImmCheckTypes;
289289

290290
public:
291-
SVEEmitter(RecordKeeper &R) : Records(R) {
291+
SVEEmitter(const RecordKeeper &R) : Records(R) {
292292
for (auto *RV : Records.getAllDerivedDefinitions("EltType"))
293293
EltTypes[RV->getNameInitAsString()] = RV->getValueAsInt("Value");
294294
for (auto *RV : Records.getAllDerivedDefinitions("MemEltType"))
@@ -397,7 +397,7 @@ class SVEEmitter {
397397
void createBuiltinZAState(raw_ostream &OS);
398398

399399
/// Create intrinsic and add it to \p Out
400-
void createIntrinsic(Record *R,
400+
void createIntrinsic(const Record *R,
401401
SmallVectorImpl<std::unique_ptr<Intrinsic>> &Out);
402402
};
403403

@@ -1151,7 +1151,7 @@ uint64_t SVEEmitter::encodeTypeFlags(const SVEType &T) {
11511151
}
11521152

11531153
void SVEEmitter::createIntrinsic(
1154-
Record *R, SmallVectorImpl<std::unique_ptr<Intrinsic>> &Out) {
1154+
const Record *R, SmallVectorImpl<std::unique_ptr<Intrinsic>> &Out) {
11551155
StringRef Name = R->getValueAsString("Name");
11561156
StringRef Proto = R->getValueAsString("Prototype");
11571157
StringRef Types = R->getValueAsString("Types");
@@ -1225,7 +1225,7 @@ void SVEEmitter::createCoreHeaderIntrinsics(raw_ostream &OS,
12251225
SVEEmitter &Emitter,
12261226
ACLEKind Kind) {
12271227
SmallVector<std::unique_ptr<Intrinsic>, 128> Defs;
1228-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
1228+
std::vector<const Record *> RV = Records.getAllDerivedDefinitions("Inst");
12291229
for (auto *R : RV)
12301230
createIntrinsic(R, Defs);
12311231

@@ -1427,7 +1427,7 @@ void SVEEmitter::createHeader(raw_ostream &OS) {
14271427
}
14281428

14291429
void SVEEmitter::createBuiltins(raw_ostream &OS) {
1430-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
1430+
std::vector<const Record *> RV = Records.getAllDerivedDefinitions("Inst");
14311431
SmallVector<std::unique_ptr<Intrinsic>, 128> Defs;
14321432
for (auto *R : RV)
14331433
createIntrinsic(R, Defs);
@@ -1469,7 +1469,7 @@ void SVEEmitter::createBuiltins(raw_ostream &OS) {
14691469
}
14701470

14711471
void SVEEmitter::createCodeGenMap(raw_ostream &OS) {
1472-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
1472+
std::vector<const Record *> RV = Records.getAllDerivedDefinitions("Inst");
14731473
SmallVector<std::unique_ptr<Intrinsic>, 128> Defs;
14741474
for (auto *R : RV)
14751475
createIntrinsic(R, Defs);
@@ -1502,7 +1502,7 @@ void SVEEmitter::createCodeGenMap(raw_ostream &OS) {
15021502
}
15031503

15041504
void SVEEmitter::createRangeChecks(raw_ostream &OS) {
1505-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
1505+
std::vector<const Record *> RV = Records.getAllDerivedDefinitions("Inst");
15061506
SmallVector<std::unique_ptr<Intrinsic>, 128> Defs;
15071507
for (auto *R : RV)
15081508
createIntrinsic(R, Defs);
@@ -1634,7 +1634,7 @@ void SVEEmitter::createSMEHeader(raw_ostream &OS) {
16341634
}
16351635

16361636
void SVEEmitter::createSMEBuiltins(raw_ostream &OS) {
1637-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
1637+
std::vector<const Record *> RV = Records.getAllDerivedDefinitions("Inst");
16381638
SmallVector<std::unique_ptr<Intrinsic>, 128> Defs;
16391639
for (auto *R : RV) {
16401640
createIntrinsic(R, Defs);
@@ -1662,7 +1662,7 @@ void SVEEmitter::createSMEBuiltins(raw_ostream &OS) {
16621662
}
16631663

16641664
void SVEEmitter::createSMECodeGenMap(raw_ostream &OS) {
1665-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
1665+
std::vector<const Record *> RV = Records.getAllDerivedDefinitions("Inst");
16661666
SmallVector<std::unique_ptr<Intrinsic>, 128> Defs;
16671667
for (auto *R : RV) {
16681668
createIntrinsic(R, Defs);
@@ -1696,7 +1696,7 @@ void SVEEmitter::createSMECodeGenMap(raw_ostream &OS) {
16961696
}
16971697

16981698
void SVEEmitter::createSMERangeChecks(raw_ostream &OS) {
1699-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
1699+
std::vector<const Record *> RV = Records.getAllDerivedDefinitions("Inst");
17001700
SmallVector<std::unique_ptr<Intrinsic>, 128> Defs;
17011701
for (auto *R : RV) {
17021702
createIntrinsic(R, Defs);
@@ -1733,7 +1733,7 @@ void SVEEmitter::createSMERangeChecks(raw_ostream &OS) {
17331733
}
17341734

17351735
void SVEEmitter::createBuiltinZAState(raw_ostream &OS) {
1736-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
1736+
std::vector<const Record *> RV = Records.getAllDerivedDefinitions("Inst");
17371737
SmallVector<std::unique_ptr<Intrinsic>, 128> Defs;
17381738
for (auto *R : RV)
17391739
createIntrinsic(R, Defs);
@@ -1773,7 +1773,7 @@ void SVEEmitter::createBuiltinZAState(raw_ostream &OS) {
17731773
}
17741774

17751775
void SVEEmitter::createStreamingAttrs(raw_ostream &OS, ACLEKind Kind) {
1776-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst");
1776+
std::vector<const Record *> RV = Records.getAllDerivedDefinitions("Inst");
17771777
SmallVector<std::unique_ptr<Intrinsic>, 128> Defs;
17781778
for (auto *R : RV)
17791779
createIntrinsic(R, Defs);
@@ -1826,55 +1826,55 @@ void SVEEmitter::createStreamingAttrs(raw_ostream &OS, ACLEKind Kind) {
18261826
}
18271827

18281828
namespace clang {
1829-
void EmitSveHeader(RecordKeeper &Records, raw_ostream &OS) {
1829+
void EmitSveHeader(const RecordKeeper &Records, raw_ostream &OS) {
18301830
SVEEmitter(Records).createHeader(OS);
18311831
}
18321832

1833-
void EmitSveBuiltins(RecordKeeper &Records, raw_ostream &OS) {
1833+
void EmitSveBuiltins(const RecordKeeper &Records, raw_ostream &OS) {
18341834
SVEEmitter(Records).createBuiltins(OS);
18351835
}
18361836

1837-
void EmitSveBuiltinCG(RecordKeeper &Records, raw_ostream &OS) {
1837+
void EmitSveBuiltinCG(const RecordKeeper &Records, raw_ostream &OS) {
18381838
SVEEmitter(Records).createCodeGenMap(OS);
18391839
}
18401840

1841-
void EmitSveRangeChecks(RecordKeeper &Records, raw_ostream &OS) {
1841+
void EmitSveRangeChecks(const RecordKeeper &Records, raw_ostream &OS) {
18421842
SVEEmitter(Records).createRangeChecks(OS);
18431843
}
18441844

1845-
void EmitSveTypeFlags(RecordKeeper &Records, raw_ostream &OS) {
1845+
void EmitSveTypeFlags(const RecordKeeper &Records, raw_ostream &OS) {
18461846
SVEEmitter(Records).createTypeFlags(OS);
18471847
}
18481848

1849-
void EmitImmCheckTypes(RecordKeeper &Records, raw_ostream &OS) {
1849+
void EmitImmCheckTypes(const RecordKeeper &Records, raw_ostream &OS) {
18501850
SVEEmitter(Records).createImmCheckTypes(OS);
18511851
}
18521852

1853-
void EmitSveStreamingAttrs(RecordKeeper &Records, raw_ostream &OS) {
1853+
void EmitSveStreamingAttrs(const RecordKeeper &Records, raw_ostream &OS) {
18541854
SVEEmitter(Records).createStreamingAttrs(OS, ACLEKind::SVE);
18551855
}
18561856

1857-
void EmitSmeHeader(RecordKeeper &Records, raw_ostream &OS) {
1857+
void EmitSmeHeader(const RecordKeeper &Records, raw_ostream &OS) {
18581858
SVEEmitter(Records).createSMEHeader(OS);
18591859
}
18601860

1861-
void EmitSmeBuiltins(RecordKeeper &Records, raw_ostream &OS) {
1861+
void EmitSmeBuiltins(const RecordKeeper &Records, raw_ostream &OS) {
18621862
SVEEmitter(Records).createSMEBuiltins(OS);
18631863
}
18641864

1865-
void EmitSmeBuiltinCG(RecordKeeper &Records, raw_ostream &OS) {
1865+
void EmitSmeBuiltinCG(const RecordKeeper &Records, raw_ostream &OS) {
18661866
SVEEmitter(Records).createSMECodeGenMap(OS);
18671867
}
18681868

1869-
void EmitSmeRangeChecks(RecordKeeper &Records, raw_ostream &OS) {
1869+
void EmitSmeRangeChecks(const RecordKeeper &Records, raw_ostream &OS) {
18701870
SVEEmitter(Records).createSMERangeChecks(OS);
18711871
}
18721872

1873-
void EmitSmeStreamingAttrs(RecordKeeper &Records, raw_ostream &OS) {
1873+
void EmitSmeStreamingAttrs(const RecordKeeper &Records, raw_ostream &OS) {
18741874
SVEEmitter(Records).createStreamingAttrs(OS, ACLEKind::SME);
18751875
}
18761876

1877-
void EmitSmeBuiltinZAState(RecordKeeper &Records, raw_ostream &OS) {
1877+
void EmitSmeBuiltinZAState(const RecordKeeper &Records, raw_ostream &OS) {
18781878
SVEEmitter(Records).createBuiltinZAState(OS);
18791879
}
18801880
} // End namespace clang

clang/utils/TableGen/TableGenBackends.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,26 @@ void EmitNeonSema(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
122122
void EmitVectorTypes(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
123123
void EmitNeonTest(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
124124

125-
void EmitImmCheckTypes(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
126-
void EmitSveHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
127-
void EmitSveBuiltins(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
128-
void EmitSveBuiltinCG(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
129-
void EmitSveTypeFlags(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
130-
void EmitSveRangeChecks(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
131-
void EmitSveStreamingAttrs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
132-
133-
void EmitSmeHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
134-
void EmitSmeBuiltins(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
135-
void EmitSmeBuiltinCG(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
136-
void EmitSmeRangeChecks(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
137-
void EmitSmeStreamingAttrs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
138-
void EmitSmeBuiltinZAState(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
125+
void EmitImmCheckTypes(const llvm::RecordKeeper &Records,
126+
llvm::raw_ostream &OS);
127+
void EmitSveHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
128+
void EmitSveBuiltins(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
129+
void EmitSveBuiltinCG(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
130+
void EmitSveTypeFlags(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
131+
void EmitSveRangeChecks(const llvm::RecordKeeper &Records,
132+
llvm::raw_ostream &OS);
133+
void EmitSveStreamingAttrs(const llvm::RecordKeeper &Records,
134+
llvm::raw_ostream &OS);
135+
136+
void EmitSmeHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
137+
void EmitSmeBuiltins(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
138+
void EmitSmeBuiltinCG(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
139+
void EmitSmeRangeChecks(const llvm::RecordKeeper &Records,
140+
llvm::raw_ostream &OS);
141+
void EmitSmeStreamingAttrs(const llvm::RecordKeeper &Records,
142+
llvm::raw_ostream &OS);
143+
void EmitSmeBuiltinZAState(const llvm::RecordKeeper &Records,
144+
llvm::raw_ostream &OS);
139145

140146
void EmitMveHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
141147
void EmitMveBuiltinDef(const llvm::RecordKeeper &Records,

0 commit comments

Comments
 (0)