Skip to content

Commit 75d8724

Browse files
authored
[clang][TableGen] Change MVE Emitter to use const RecordKeeper (#108500)
Change MVE 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 d757bbf commit 75d8724

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

clang/utils/TableGen/MveEmitter.cpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ class ACLEIntrinsic {
958958
";\n";
959959
}
960960

961-
ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param);
961+
ACLEIntrinsic(EmitterBase &ME, const Record *R, const Type *Param);
962962
};
963963

964964
// -----------------------------------------------------------------------------
@@ -988,7 +988,7 @@ class EmitterBase {
988988
const ScalarType *getScalarType(StringRef Name) {
989989
return ScalarTypes[std::string(Name)].get();
990990
}
991-
const ScalarType *getScalarType(Record *R) {
991+
const ScalarType *getScalarType(const Record *R) {
992992
return getScalarType(R->getName());
993993
}
994994
const VectorType *getVectorType(const ScalarType *ST, unsigned Lanes) {
@@ -1028,7 +1028,7 @@ class EmitterBase {
10281028
// the Params list in the Tablegen record for the intrinsic), which is used
10291029
// to expand Tablegen classes like 'Vector' which mean something different in
10301030
// each member of a parametric family.
1031-
const Type *getType(Record *R, const Type *Param);
1031+
const Type *getType(const Record *R, const Type *Param);
10321032
const Type *getType(DagInit *D, const Type *Param);
10331033
const Type *getType(Init *I, const Type *Param);
10341034

@@ -1046,7 +1046,7 @@ class EmitterBase {
10461046

10471047
// Constructor and top-level functions.
10481048

1049-
EmitterBase(RecordKeeper &Records);
1049+
EmitterBase(const RecordKeeper &Records);
10501050
virtual ~EmitterBase() = default;
10511051

10521052
virtual void EmitHeader(raw_ostream &OS) = 0;
@@ -1065,7 +1065,7 @@ const Type *EmitterBase::getType(Init *I, const Type *Param) {
10651065
PrintFatalError("Could not convert this value into a type");
10661066
}
10671067

1068-
const Type *EmitterBase::getType(Record *R, const Type *Param) {
1068+
const Type *EmitterBase::getType(const Record *R, const Type *Param) {
10691069
// Pass to a subfield of any wrapper records. We don't expect more than one
10701070
// of these: immediate operands are used as plain numbers rather than as
10711071
// llvm::Value, so it's meaningless to promote their type anyway.
@@ -1088,7 +1088,7 @@ const Type *EmitterBase::getType(DagInit *D, const Type *Param) {
10881088
// The meat of the getType system: types in the Tablegen are represented by a
10891089
// dag whose operators select sub-cases of this function.
10901090

1091-
Record *Op = cast<DefInit>(D->getOperator())->getDef();
1091+
const Record *Op = cast<DefInit>(D->getOperator())->getDef();
10921092
if (!Op->isSubClassOf("ComplexTypeOp"))
10931093
PrintFatalError(
10941094
"Expected ComplexTypeOp as dag operator in type expression");
@@ -1154,7 +1154,7 @@ const Type *EmitterBase::getType(DagInit *D, const Type *Param) {
11541154

11551155
Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
11561156
const Type *Param) {
1157-
Record *Op = cast<DefInit>(D->getOperator())->getDef();
1157+
const Record *Op = cast<DefInit>(D->getOperator())->getDef();
11581158

11591159
if (Op->getName() == "seq") {
11601160
Result::Scope SubScope = Scope;
@@ -1211,7 +1211,7 @@ Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
12111211
} else if (Op->getName() == "unsignedflag") {
12121212
if (D->getNumArgs() != 1)
12131213
PrintFatalError("unsignedflag should have exactly one argument");
1214-
Record *TypeRec = cast<DefInit>(D->getArg(0))->getDef();
1214+
const Record *TypeRec = cast<DefInit>(D->getArg(0))->getDef();
12151215
if (!TypeRec->isSubClassOf("Type"))
12161216
PrintFatalError("unsignedflag's argument should be a type");
12171217
if (const auto *ST = dyn_cast<ScalarType>(getType(TypeRec, Param))) {
@@ -1223,7 +1223,7 @@ Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
12231223
} else if (Op->getName() == "bitsize") {
12241224
if (D->getNumArgs() != 1)
12251225
PrintFatalError("bitsize should have exactly one argument");
1226-
Record *TypeRec = cast<DefInit>(D->getArg(0))->getDef();
1226+
const Record *TypeRec = cast<DefInit>(D->getArg(0))->getDef();
12271227
if (!TypeRec->isSubClassOf("Type"))
12281228
PrintFatalError("bitsize's argument should be a type");
12291229
if (const auto *ST = dyn_cast<ScalarType>(getType(TypeRec, Param))) {
@@ -1239,7 +1239,7 @@ Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
12391239
if (Op->isSubClassOf("IRBuilderBase")) {
12401240
std::set<unsigned> AddressArgs;
12411241
std::map<unsigned, std::string> IntegerArgs;
1242-
for (Record *sp : Op->getValueAsListOfDefs("special_params")) {
1242+
for (const Record *sp : Op->getValueAsListOfDefs("special_params")) {
12431243
unsigned Index = sp->getValueAsInt("index");
12441244
if (sp->isSubClassOf("IRBuilderAddrParam")) {
12451245
AddressArgs.insert(Index);
@@ -1251,7 +1251,7 @@ Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
12511251
Args, AddressArgs, IntegerArgs);
12521252
} else if (Op->isSubClassOf("IRIntBase")) {
12531253
std::vector<const Type *> ParamTypes;
1254-
for (Record *RParam : Op->getValueAsListOfDefs("params"))
1254+
for (const Record *RParam : Op->getValueAsListOfDefs("params"))
12551255
ParamTypes.push_back(getType(RParam, Param));
12561256
std::string IntName = std::string(Op->getValueAsString("intname"));
12571257
if (Op->getValueAsBit("appendKind"))
@@ -1294,7 +1294,7 @@ Result::Ptr EmitterBase::getCodeForDagArg(DagInit *D, unsigned ArgNum,
12941294
return getCodeForDag(DI, Scope, Param);
12951295

12961296
if (auto *DI = dyn_cast<DefInit>(Arg)) {
1297-
Record *Rec = DI->getDef();
1297+
const Record *Rec = DI->getDef();
12981298
if (Rec->isSubClassOf("Type")) {
12991299
const Type *T = getType(Rec, Param);
13001300
return std::make_shared<TypeResult>(T);
@@ -1328,7 +1328,8 @@ Result::Ptr EmitterBase::getCodeForArg(unsigned ArgNum, const Type *ArgType,
13281328
return V;
13291329
}
13301330

1331-
ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
1331+
ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, const Record *R,
1332+
const Type *Param)
13321333
: ReturnType(ME.getType(R->getValueAsDef("ret"), Param)) {
13331334
// Derive the intrinsic's full name, by taking the name of the
13341335
// Tablegen record (or override) and appending the suffix from its
@@ -1346,7 +1347,7 @@ ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
13461347
// full name as specified by its 'pnt' member ('polymorphic name type'),
13471348
// which indicates how many type suffixes to remove, and any other piece of
13481349
// the name that should be removed.
1349-
Record *PolymorphicNameType = R->getValueAsDef("pnt");
1350+
const Record *PolymorphicNameType = R->getValueAsDef("pnt");
13501351
SmallVector<StringRef, 8> NameParts;
13511352
StringRef(FullName).split(NameParts, '_');
13521353
for (unsigned i = 0, e = PolymorphicNameType->getValueAsInt(
@@ -1393,11 +1394,11 @@ ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
13931394
// what values it can take, for Sema checking.
13941395
bool Immediate = false;
13951396
if (auto TypeDI = dyn_cast<DefInit>(TypeInit)) {
1396-
Record *TypeRec = TypeDI->getDef();
1397+
const Record *TypeRec = TypeDI->getDef();
13971398
if (TypeRec->isSubClassOf("Immediate")) {
13981399
Immediate = true;
13991400

1400-
Record *Bounds = TypeRec->getValueAsDef("bounds");
1401+
const Record *Bounds = TypeRec->getValueAsDef("bounds");
14011402
ImmediateArg &IA = ImmediateArgs[i];
14021403
if (Bounds->isSubClassOf("IB_ConstRange")) {
14031404
IA.boundsType = ImmediateArg::BoundsType::ExplicitRange;
@@ -1440,7 +1441,7 @@ ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
14401441
// Finally, go through the codegen dag and translate it into a Result object
14411442
// (with an arbitrary DAG of depended-on Results hanging off it).
14421443
DagInit *CodeDag = R->getValueAsDag("codegen");
1443-
Record *MainOp = cast<DefInit>(CodeDag->getOperator())->getDef();
1444+
const Record *MainOp = cast<DefInit>(CodeDag->getOperator())->getDef();
14441445
if (MainOp->isSubClassOf("CustomCodegen")) {
14451446
// Or, if it's the special case of CustomCodegen, just accumulate
14461447
// a list of parameters we're going to assign to variables before
@@ -1464,21 +1465,21 @@ ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
14641465
}
14651466
}
14661467

1467-
EmitterBase::EmitterBase(RecordKeeper &Records) {
1468+
EmitterBase::EmitterBase(const RecordKeeper &Records) {
14681469
// Construct the whole EmitterBase.
14691470

14701471
// First, look up all the instances of PrimitiveType. This gives us the list
14711472
// of vector typedefs we have to put in arm_mve.h, and also allows us to
14721473
// collect all the useful ScalarType instances into a big list so that we can
14731474
// use it for operations such as 'find the unsigned version of this signed
14741475
// integer type'.
1475-
for (Record *R : Records.getAllDerivedDefinitions("PrimitiveType"))
1476+
for (const Record *R : Records.getAllDerivedDefinitions("PrimitiveType"))
14761477
ScalarTypes[std::string(R->getName())] = std::make_unique<ScalarType>(R);
14771478

14781479
// Now go through the instances of Intrinsic, and for each one, iterate
14791480
// through its list of type parameters making an ACLEIntrinsic for each one.
1480-
for (Record *R : Records.getAllDerivedDefinitions("Intrinsic")) {
1481-
for (Record *RParam : R->getValueAsListOfDefs("params")) {
1481+
for (const Record *R : Records.getAllDerivedDefinitions("Intrinsic")) {
1482+
for (const Record *RParam : R->getValueAsListOfDefs("params")) {
14821483
const Type *Param = getType(RParam, getVoidType());
14831484
auto Intrinsic = std::make_unique<ACLEIntrinsic>(*this, R, Param);
14841485
ACLEIntrinsics[Intrinsic->fullName()] = std::move(Intrinsic);
@@ -1752,7 +1753,7 @@ void EmitterBase::GroupSemaChecks(
17521753

17531754
class MveEmitter : public EmitterBase {
17541755
public:
1755-
MveEmitter(RecordKeeper &Records) : EmitterBase(Records){};
1756+
MveEmitter(const RecordKeeper &Records) : EmitterBase(Records) {}
17561757
void EmitHeader(raw_ostream &OS) override;
17571758
void EmitBuiltinDef(raw_ostream &OS) override;
17581759
void EmitBuiltinSema(raw_ostream &OS) override;
@@ -2010,14 +2011,14 @@ class CdeEmitter : public EmitterBase {
20102011
std::map<StringRef, FunctionMacro> FunctionMacros;
20112012

20122013
public:
2013-
CdeEmitter(RecordKeeper &Records);
2014+
CdeEmitter(const RecordKeeper &Records);
20142015
void EmitHeader(raw_ostream &OS) override;
20152016
void EmitBuiltinDef(raw_ostream &OS) override;
20162017
void EmitBuiltinSema(raw_ostream &OS) override;
20172018
};
20182019

2019-
CdeEmitter::CdeEmitter(RecordKeeper &Records) : EmitterBase(Records) {
2020-
for (Record *R : Records.getAllDerivedDefinitions("FunctionMacro"))
2020+
CdeEmitter::CdeEmitter(const RecordKeeper &Records) : EmitterBase(Records) {
2021+
for (const Record *R : Records.getAllDerivedDefinitions("FunctionMacro"))
20212022
FunctionMacros.emplace(R->getName(), FunctionMacro(*R));
20222023
}
20232024

@@ -2179,45 +2180,45 @@ namespace clang {
21792180

21802181
// MVE
21812182

2182-
void EmitMveHeader(RecordKeeper &Records, raw_ostream &OS) {
2183+
void EmitMveHeader(const RecordKeeper &Records, raw_ostream &OS) {
21832184
MveEmitter(Records).EmitHeader(OS);
21842185
}
21852186

2186-
void EmitMveBuiltinDef(RecordKeeper &Records, raw_ostream &OS) {
2187+
void EmitMveBuiltinDef(const RecordKeeper &Records, raw_ostream &OS) {
21872188
MveEmitter(Records).EmitBuiltinDef(OS);
21882189
}
21892190

2190-
void EmitMveBuiltinSema(RecordKeeper &Records, raw_ostream &OS) {
2191+
void EmitMveBuiltinSema(const RecordKeeper &Records, raw_ostream &OS) {
21912192
MveEmitter(Records).EmitBuiltinSema(OS);
21922193
}
21932194

2194-
void EmitMveBuiltinCG(RecordKeeper &Records, raw_ostream &OS) {
2195+
void EmitMveBuiltinCG(const RecordKeeper &Records, raw_ostream &OS) {
21952196
MveEmitter(Records).EmitBuiltinCG(OS);
21962197
}
21972198

2198-
void EmitMveBuiltinAliases(RecordKeeper &Records, raw_ostream &OS) {
2199+
void EmitMveBuiltinAliases(const RecordKeeper &Records, raw_ostream &OS) {
21992200
MveEmitter(Records).EmitBuiltinAliases(OS);
22002201
}
22012202

22022203
// CDE
22032204

2204-
void EmitCdeHeader(RecordKeeper &Records, raw_ostream &OS) {
2205+
void EmitCdeHeader(const RecordKeeper &Records, raw_ostream &OS) {
22052206
CdeEmitter(Records).EmitHeader(OS);
22062207
}
22072208

2208-
void EmitCdeBuiltinDef(RecordKeeper &Records, raw_ostream &OS) {
2209+
void EmitCdeBuiltinDef(const RecordKeeper &Records, raw_ostream &OS) {
22092210
CdeEmitter(Records).EmitBuiltinDef(OS);
22102211
}
22112212

2212-
void EmitCdeBuiltinSema(RecordKeeper &Records, raw_ostream &OS) {
2213+
void EmitCdeBuiltinSema(const RecordKeeper &Records, raw_ostream &OS) {
22132214
CdeEmitter(Records).EmitBuiltinSema(OS);
22142215
}
22152216

2216-
void EmitCdeBuiltinCG(RecordKeeper &Records, raw_ostream &OS) {
2217+
void EmitCdeBuiltinCG(const RecordKeeper &Records, raw_ostream &OS) {
22172218
CdeEmitter(Records).EmitBuiltinCG(OS);
22182219
}
22192220

2220-
void EmitCdeBuiltinAliases(RecordKeeper &Records, raw_ostream &OS) {
2221+
void EmitCdeBuiltinAliases(const RecordKeeper &Records, raw_ostream &OS) {
22212222
CdeEmitter(Records).EmitBuiltinAliases(OS);
22222223
}
22232224

clang/utils/TableGen/TableGenBackends.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,28 @@ void EmitSmeRangeChecks(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
137137
void EmitSmeStreamingAttrs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
138138
void EmitSmeBuiltinZAState(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
139139

140-
void EmitMveHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
141-
void EmitMveBuiltinDef(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
142-
void EmitMveBuiltinSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
143-
void EmitMveBuiltinCG(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
144-
void EmitMveBuiltinAliases(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
140+
void EmitMveHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
141+
void EmitMveBuiltinDef(const llvm::RecordKeeper &Records,
142+
llvm::raw_ostream &OS);
143+
void EmitMveBuiltinSema(const llvm::RecordKeeper &Records,
144+
llvm::raw_ostream &OS);
145+
void EmitMveBuiltinCG(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
146+
void EmitMveBuiltinAliases(const llvm::RecordKeeper &Records,
147+
llvm::raw_ostream &OS);
145148

146149
void EmitRVVHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
147150
void EmitRVVBuiltins(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
148151
void EmitRVVBuiltinCG(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
149152
void EmitRVVBuiltinSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
150153

151-
void EmitCdeHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
152-
void EmitCdeBuiltinDef(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
153-
void EmitCdeBuiltinSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
154-
void EmitCdeBuiltinCG(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
155-
void EmitCdeBuiltinAliases(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
154+
void EmitCdeHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
155+
void EmitCdeBuiltinDef(const llvm::RecordKeeper &Records,
156+
llvm::raw_ostream &OS);
157+
void EmitCdeBuiltinSema(const llvm::RecordKeeper &Records,
158+
llvm::raw_ostream &OS);
159+
void EmitCdeBuiltinCG(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
160+
void EmitCdeBuiltinAliases(const llvm::RecordKeeper &Records,
161+
llvm::raw_ostream &OS);
156162

157163
void EmitClangAttrDocs(const llvm::RecordKeeper &Records,
158164
llvm::raw_ostream &OS);

0 commit comments

Comments
 (0)