Skip to content

Commit 5831eed

Browse files
authored
[Clang][TableGen] Change Opcodes Emitter to use const Record * (#110588)
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 52e7c69 commit 5831eed

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

clang/utils/TableGen/ClangOpcodesEmitter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void Enumerate(const Record *R, StringRef N,
6969

7070
if (const auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) {
7171
for (const auto *Type :
72-
TypeClass->getDef()->getValueAsListOfDefs("Types")) {
72+
TypeClass->getDef()->getValueAsListOfConstDefs("Types")) {
7373
TypePath.push_back(Type);
7474
Rec(I + 1, ID + Type->getName());
7575
TypePath.pop_back();
@@ -117,7 +117,7 @@ void ClangOpcodesEmitter::EmitInterp(raw_ostream &OS, StringRef N,
117117
[this, R, &OS, &N](ArrayRef<const Record *> TS, const Twine &ID) {
118118
bool CanReturn = R->getValueAsBit("CanReturn");
119119
bool ChangesPC = R->getValueAsBit("ChangesPC");
120-
const auto &Args = R->getValueAsListOfDefs("Args");
120+
const auto &Args = R->getValueAsListOfConstDefs("Args");
121121

122122
OS << "case OP_" << ID << ": {\n";
123123

@@ -176,7 +176,7 @@ void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N,
176176
OS << " PrintName(\"" << ID << "\");\n";
177177
OS << " OS << \"\\t\"";
178178

179-
for (const auto *Arg : R->getValueAsListOfDefs("Args")) {
179+
for (const auto *Arg : R->getValueAsListOfConstDefs("Args")) {
180180
OS << " << ReadArg<" << Arg->getValueAsString("Name") << ">(P, PC)";
181181
OS << " << \" \"";
182182
}
@@ -194,7 +194,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N,
194194

195195
OS << "#ifdef GET_LINK_IMPL\n";
196196
Enumerate(R, N, [R, &OS](ArrayRef<const Record *>, const Twine &ID) {
197-
const auto &Args = R->getValueAsListOfDefs("Args");
197+
const auto &Args = R->getValueAsListOfConstDefs("Args");
198198

199199
// Emit the list of arguments.
200200
OS << "bool ByteCodeEmitter::emit" << ID << "(";
@@ -227,7 +227,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N,
227227
void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
228228
const Record *R) {
229229
OS << "#if defined(GET_EVAL_PROTO) || defined(GET_LINK_PROTO)\n";
230-
auto Args = R->getValueAsListOfDefs("Args");
230+
auto Args = R->getValueAsListOfConstDefs("Args");
231231
Enumerate(R, N, [&OS, &Args](ArrayRef<const Record *> TS, const Twine &ID) {
232232
OS << "bool emit" << ID << "(";
233233
for (size_t I = 0, N = Args.size(); I < N; ++I) {
@@ -268,7 +268,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
268268
return;
269269

270270
const auto *Types = R->getValueAsListInit("Types");
271-
const auto &Args = R->getValueAsListOfDefs("Args");
271+
const auto &Args = R->getValueAsListOfConstDefs("Args");
272272

273273
Twine EmitFuncName = "emit" + N;
274274

@@ -333,7 +333,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
333333
// Print a switch statement selecting T.
334334
if (auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) {
335335
OS << " switch (T" << I << ") {\n";
336-
auto Cases = TypeClass->getDef()->getValueAsListOfDefs("Types");
336+
auto Cases = TypeClass->getDef()->getValueAsListOfConstDefs("Types");
337337
for (auto *Case : Cases) {
338338
OS << " case PT_" << Case->getName() << ":\n";
339339
TS.push_back(Case);
@@ -364,7 +364,7 @@ void ClangOpcodesEmitter::EmitEval(raw_ostream &OS, StringRef N,
364364
OS << "#ifdef GET_EVAL_IMPL\n";
365365
Enumerate(R, N,
366366
[this, R, &N, &OS](ArrayRef<const Record *> TS, const Twine &ID) {
367-
auto Args = R->getValueAsListOfDefs("Args");
367+
auto Args = R->getValueAsListOfConstDefs("Args");
368368

369369
OS << "bool EvalEmitter::emit" << ID << "(";
370370
for (size_t I = 0, N = Args.size(); I < N; ++I) {

0 commit comments

Comments
 (0)