Skip to content

Commit 2b01452

Browse files
authored
[LLVM][TableGen] Use const Record pointers in PredicateExpander (#109365)
Use const Record pointers in PredicateExpander. 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 d109636 commit 2b01452

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

llvm/utils/TableGen/Common/PredicateExpander.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS, const Record *Inst) {
139139
}
140140

141141
void PredicateExpander::expandCheckOpcode(raw_ostream &OS,
142-
const RecVec &Opcodes) {
142+
ArrayRef<const Record *> Opcodes) {
143143
assert(!Opcodes.empty() && "Expected at least one opcode to check!");
144144
bool First = true;
145145

@@ -169,16 +169,15 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS,
169169
}
170170

171171
void PredicateExpander::expandCheckPseudo(raw_ostream &OS,
172-
const RecVec &Opcodes) {
172+
ArrayRef<const Record *> Opcodes) {
173173
if (shouldExpandForMC())
174174
expandFalse(OS);
175175
else
176176
expandCheckOpcode(OS, Opcodes);
177177
}
178178

179-
void PredicateExpander::expandPredicateSequence(raw_ostream &OS,
180-
const RecVec &Sequence,
181-
bool IsCheckAll) {
179+
void PredicateExpander::expandPredicateSequence(
180+
raw_ostream &OS, ArrayRef<const Record *> Sequence, bool IsCheckAll) {
182181
assert(!Sequence.empty() && "Found an invalid empty predicate set!");
183182
if (Sequence.size() == 1)
184183
return expandPredicate(OS, Sequence[0]);
@@ -267,8 +266,7 @@ void PredicateExpander::expandReturnStatement(raw_ostream &OS,
267266

268267
void PredicateExpander::expandOpcodeSwitchCase(raw_ostream &OS,
269268
const Record *Rec) {
270-
const RecVec &Opcodes = Rec->getValueAsListOfDefs("Opcodes");
271-
for (const Record *Opcode : Opcodes) {
269+
for (const Record *Opcode : Rec->getValueAsListOfDefs("Opcodes")) {
272270
OS.indent(getIndentLevel() * 2);
273271
OS << "case " << Opcode->getValueAsString("Namespace")
274272
<< "::" << Opcode->getName() << ":\n";
@@ -280,9 +278,8 @@ void PredicateExpander::expandOpcodeSwitchCase(raw_ostream &OS,
280278
decreaseIndentLevel();
281279
}
282280

283-
void PredicateExpander::expandOpcodeSwitchStatement(raw_ostream &OS,
284-
const RecVec &Cases,
285-
const Record *Default) {
281+
void PredicateExpander::expandOpcodeSwitchStatement(
282+
raw_ostream &OS, ArrayRef<const Record *> Cases, const Record *Default) {
286283
std::string Buffer;
287284
raw_string_ostream SS(Buffer);
288285

@@ -310,7 +307,7 @@ void PredicateExpander::expandOpcodeSwitchStatement(raw_ostream &OS,
310307
void PredicateExpander::expandStatement(raw_ostream &OS, const Record *Rec) {
311308
// Assume that padding has been added by the caller.
312309
if (Rec->isSubClassOf("MCOpcodeSwitchStatement")) {
313-
expandOpcodeSwitchStatement(OS, Rec->getValueAsListOfDefs("Cases"),
310+
expandOpcodeSwitchStatement(OS, Rec->getValueAsListOfConstDefs("Cases"),
314311
Rec->getValueAsDef("DefaultCase"));
315312
return;
316313
}
@@ -461,13 +458,13 @@ void STIPredicateExpander::expandHeader(raw_ostream &OS,
461458

462459
void STIPredicateExpander::expandPrologue(raw_ostream &OS,
463460
const STIPredicateFunction &Fn) {
464-
RecVec Delegates = Fn.getDeclaration()->getValueAsListOfDefs("Delegates");
465461
bool UpdatesOpcodeMask =
466462
Fn.getDeclaration()->getValueAsBit("UpdatesOpcodeMask");
467463

468464
increaseIndentLevel();
469465
unsigned IndentLevel = getIndentLevel();
470-
for (const Record *Delegate : Delegates) {
466+
for (const Record *Delegate :
467+
Fn.getDeclaration()->getValueAsListOfDefs("Delegates")) {
471468
OS.indent(IndentLevel * 2);
472469
OS << "if (" << Delegate->getValueAsString("Name") << "(MI";
473470
if (UpdatesOpcodeMask)

llvm/utils/TableGen/Common/PredicateExpander.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#ifndef LLVM_UTILS_TABLEGEN_COMMON_PREDICATEEXPANDER_H
1717
#define LLVM_UTILS_TABLEGEN_COMMON_PREDICATEEXPANDER_H
1818

19+
#include "llvm/ADT/ArrayRef.h"
1920
#include "llvm/ADT/StringRef.h"
20-
#include <vector>
2121

2222
namespace llvm {
2323

@@ -52,7 +52,6 @@ class PredicateExpander {
5252
void increaseIndentLevel() { ++IndentLevel; }
5353
void decreaseIndentLevel() { --IndentLevel; }
5454

55-
using RecVec = std::vector<Record *>;
5655
void expandTrue(raw_ostream &OS);
5756
void expandFalse(raw_ostream &OS);
5857
void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal,
@@ -73,9 +72,10 @@ class PredicateExpander {
7372
void expandCheckNumOperands(raw_ostream &OS, int NumOps);
7473
void expandCheckOpcode(raw_ostream &OS, const Record *Inst);
7574

76-
void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes);
77-
void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes);
78-
void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
75+
void expandCheckPseudo(raw_ostream &OS, ArrayRef<const Record *> Opcodes);
76+
void expandCheckOpcode(raw_ostream &OS, ArrayRef<const Record *> Opcodes);
77+
void expandPredicateSequence(raw_ostream &OS,
78+
ArrayRef<const Record *> Sequence,
7979
bool IsCheckAll);
8080
void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName);
8181
void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex);
@@ -91,7 +91,8 @@ class PredicateExpander {
9191
void expandPredicate(raw_ostream &OS, const Record *Rec);
9292
void expandReturnStatement(raw_ostream &OS, const Record *Rec);
9393
void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec);
94-
void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
94+
void expandOpcodeSwitchStatement(raw_ostream &OS,
95+
ArrayRef<const Record *> Cases,
9596
const Record *Default);
9697
void expandStatement(raw_ostream &OS, const Record *Rec);
9798
};

0 commit comments

Comments
 (0)