Skip to content

Commit 9284e18

Browse files
authored
[LLVM][TableGen] Change DAGISel code to use const RecordKeeper (#109038)
Change DAGISel code 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 a800ffa commit 9284e18

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

llvm/utils/TableGen/DAGISelEmitter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ namespace {
2525
/// DAGISelEmitter - The top-level class which coordinates construction
2626
/// and emission of the instruction selector.
2727
class DAGISelEmitter {
28-
RecordKeeper &Records; // Just so we can get at the timing functions.
29-
CodeGenDAGPatterns CGP;
28+
const RecordKeeper &Records; // Just so we can get at the timing functions.
29+
const CodeGenDAGPatterns CGP;
3030

3131
public:
32-
explicit DAGISelEmitter(RecordKeeper &R) : Records(R), CGP(R) {}
32+
explicit DAGISelEmitter(const RecordKeeper &R) : Records(R), CGP(R) {}
3333
void run(raw_ostream &OS);
3434
};
3535
} // End anonymous namespace
@@ -81,8 +81,8 @@ namespace {
8181
// In particular, we want to match maximal patterns first and lowest cost within
8282
// a particular complexity first.
8383
struct PatternSortingPredicate {
84-
PatternSortingPredicate(CodeGenDAGPatterns &cgp) : CGP(cgp) {}
85-
CodeGenDAGPatterns &CGP;
84+
PatternSortingPredicate(const CodeGenDAGPatterns &cgp) : CGP(cgp) {}
85+
const CodeGenDAGPatterns &CGP;
8686

8787
bool operator()(const PatternToMatch *LHS, const PatternToMatch *RHS) {
8888
const TreePatternNode &LT = LHS->getSrcPattern();

llvm/utils/TableGen/DAGISelMatcherGen.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace llvm;
2323
/// getRegisterValueType - Look up and return the ValueType of the specified
2424
/// register. If the register is a member of multiple register classes, they
2525
/// must all have the same type.
26-
static MVT::SimpleValueType getRegisterValueType(Record *R,
26+
static MVT::SimpleValueType getRegisterValueType(const Record *R,
2727
const CodeGenTarget &T) {
2828
bool FoundRC = false;
2929
MVT::SimpleValueType VT = MVT::Other;
@@ -91,7 +91,7 @@ class MatcherGen {
9191
/// PhysRegInputs - List list has an entry for each explicitly specified
9292
/// physreg input to the pattern. The first elt is the Register node, the
9393
/// second is the recorded slot number the input pattern match saved it in.
94-
SmallVector<std::pair<Record *, unsigned>, 2> PhysRegInputs;
94+
SmallVector<std::pair<const Record *, unsigned>, 2> PhysRegInputs;
9595

9696
/// Matcher - This is the top level of the generated matcher, the result.
9797
Matcher *TheMatcher;
@@ -220,13 +220,13 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode &N) {
220220
return;
221221
}
222222

223-
DefInit *DI = dyn_cast<DefInit>(N.getLeafValue());
223+
const DefInit *DI = dyn_cast<DefInit>(N.getLeafValue());
224224
if (!DI) {
225225
errs() << "Unknown leaf kind: " << N << "\n";
226226
abort();
227227
}
228228

229-
Record *LeafRec = DI->getDef();
229+
const Record *LeafRec = DI->getDef();
230230

231231
// A ValueType leaf node can represent a register when named, or itself when
232232
// unnamed.
@@ -673,7 +673,7 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
673673

674674
// If this is an explicit register reference, handle it.
675675
if (DefInit *DI = dyn_cast<DefInit>(N.getLeafValue())) {
676-
Record *Def = DI->getDef();
676+
const Record *Def = DI->getDef();
677677
if (Def->isSubClassOf("Register")) {
678678
const CodeGenRegister *Reg = CGP.getTargetInfo().getRegBank().getReg(Def);
679679
AddMatcher(new EmitRegisterMatcher(Reg, N.getSimpleType(0)));
@@ -690,7 +690,7 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
690690
if (Def->getName() == "undef_tied_input") {
691691
MVT::SimpleValueType ResultVT = N.getSimpleType(0);
692692
auto IDOperandNo = NextRecordedOperandNo++;
693-
Record *ImpDef = Def->getRecords().getDef("IMPLICIT_DEF");
693+
const Record *ImpDef = Def->getRecords().getDef("IMPLICIT_DEF");
694694
CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(ImpDef);
695695
AddMatcher(new EmitNodeMatcher(II, ResultVT, std::nullopt, false, false,
696696
false, false, -1, IDOperandNo));
@@ -907,11 +907,11 @@ void MatcherGen::EmitResultInstructionAsOperand(
907907
if (isRoot && !Pattern.getDstRegs().empty()) {
908908
// If the root came from an implicit def in the instruction handling stuff,
909909
// don't re-add it.
910-
Record *HandledReg = nullptr;
910+
const Record *HandledReg = nullptr;
911911
if (II.HasOneImplicitDefWithKnownVT(CGT) != MVT::Other)
912912
HandledReg = II.ImplicitDefs[0];
913913

914-
for (Record *Reg : Pattern.getDstRegs()) {
914+
for (const Record *Reg : Pattern.getDstRegs()) {
915915
if (!Reg->isSubClassOf("Register") || Reg == HandledReg)
916916
continue;
917917
ResultVTs.push_back(getRegisterValueType(Reg, CGT));
@@ -1042,7 +1042,7 @@ void MatcherGen::EmitResultCode() {
10421042
if (!Pattern.getDstRegs().empty()) {
10431043
// If the root came from an implicit def in the instruction handling stuff,
10441044
// don't re-add it.
1045-
Record *HandledReg = nullptr;
1045+
const Record *HandledReg = nullptr;
10461046
const TreePatternNode &DstPat = Pattern.getDstPattern();
10471047
if (!DstPat.isLeaf() && DstPat.getOperator()->isSubClassOf("Instruction")) {
10481048
const CodeGenTarget &CGT = CGP.getTargetInfo();
@@ -1052,7 +1052,7 @@ void MatcherGen::EmitResultCode() {
10521052
HandledReg = II.ImplicitDefs[0];
10531053
}
10541054

1055-
for (Record *Reg : Pattern.getDstRegs()) {
1055+
for (const Record *Reg : Pattern.getDstRegs()) {
10561056
if (!Reg->isSubClassOf("Register") || Reg == HandledReg)
10571057
continue;
10581058
++NumSrcResults;

0 commit comments

Comments
 (0)