[clang] [clang][TableGen] Change MVE Emitter to use const RecordKeeper (PR #108500)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 13 05:32:19 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/108500.diff
2 Files Affected:
- (modified) clang/utils/TableGen/MveEmitter.cpp (+36-35)
- (modified) clang/utils/TableGen/TableGenBackends.h (+16-10)
``````````diff
diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp
index bb4f091604f5e4..6cfaa891241fa9 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -958,7 +958,7 @@ class ACLEIntrinsic {
";\n";
}
- ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param);
+ ACLEIntrinsic(EmitterBase &ME, const Record *R, const Type *Param);
};
// -----------------------------------------------------------------------------
@@ -988,7 +988,7 @@ class EmitterBase {
const ScalarType *getScalarType(StringRef Name) {
return ScalarTypes[std::string(Name)].get();
}
- const ScalarType *getScalarType(Record *R) {
+ const ScalarType *getScalarType(const Record *R) {
return getScalarType(R->getName());
}
const VectorType *getVectorType(const ScalarType *ST, unsigned Lanes) {
@@ -1028,7 +1028,7 @@ class EmitterBase {
// the Params list in the Tablegen record for the intrinsic), which is used
// to expand Tablegen classes like 'Vector' which mean something different in
// each member of a parametric family.
- const Type *getType(Record *R, const Type *Param);
+ const Type *getType(const Record *R, const Type *Param);
const Type *getType(DagInit *D, const Type *Param);
const Type *getType(Init *I, const Type *Param);
@@ -1046,7 +1046,7 @@ class EmitterBase {
// Constructor and top-level functions.
- EmitterBase(RecordKeeper &Records);
+ EmitterBase(const RecordKeeper &Records);
virtual ~EmitterBase() = default;
virtual void EmitHeader(raw_ostream &OS) = 0;
@@ -1065,7 +1065,7 @@ const Type *EmitterBase::getType(Init *I, const Type *Param) {
PrintFatalError("Could not convert this value into a type");
}
-const Type *EmitterBase::getType(Record *R, const Type *Param) {
+const Type *EmitterBase::getType(const Record *R, const Type *Param) {
// Pass to a subfield of any wrapper records. We don't expect more than one
// of these: immediate operands are used as plain numbers rather than as
// llvm::Value, so it's meaningless to promote their type anyway.
@@ -1088,7 +1088,7 @@ const Type *EmitterBase::getType(DagInit *D, const Type *Param) {
// The meat of the getType system: types in the Tablegen are represented by a
// dag whose operators select sub-cases of this function.
- Record *Op = cast<DefInit>(D->getOperator())->getDef();
+ const Record *Op = cast<DefInit>(D->getOperator())->getDef();
if (!Op->isSubClassOf("ComplexTypeOp"))
PrintFatalError(
"Expected ComplexTypeOp as dag operator in type expression");
@@ -1154,7 +1154,7 @@ const Type *EmitterBase::getType(DagInit *D, const Type *Param) {
Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
const Type *Param) {
- Record *Op = cast<DefInit>(D->getOperator())->getDef();
+ const Record *Op = cast<DefInit>(D->getOperator())->getDef();
if (Op->getName() == "seq") {
Result::Scope SubScope = Scope;
@@ -1211,7 +1211,7 @@ Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
} else if (Op->getName() == "unsignedflag") {
if (D->getNumArgs() != 1)
PrintFatalError("unsignedflag should have exactly one argument");
- Record *TypeRec = cast<DefInit>(D->getArg(0))->getDef();
+ const Record *TypeRec = cast<DefInit>(D->getArg(0))->getDef();
if (!TypeRec->isSubClassOf("Type"))
PrintFatalError("unsignedflag's argument should be a type");
if (const auto *ST = dyn_cast<ScalarType>(getType(TypeRec, Param))) {
@@ -1223,7 +1223,7 @@ Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
} else if (Op->getName() == "bitsize") {
if (D->getNumArgs() != 1)
PrintFatalError("bitsize should have exactly one argument");
- Record *TypeRec = cast<DefInit>(D->getArg(0))->getDef();
+ const Record *TypeRec = cast<DefInit>(D->getArg(0))->getDef();
if (!TypeRec->isSubClassOf("Type"))
PrintFatalError("bitsize's argument should be a type");
if (const auto *ST = dyn_cast<ScalarType>(getType(TypeRec, Param))) {
@@ -1239,7 +1239,7 @@ Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
if (Op->isSubClassOf("IRBuilderBase")) {
std::set<unsigned> AddressArgs;
std::map<unsigned, std::string> IntegerArgs;
- for (Record *sp : Op->getValueAsListOfDefs("special_params")) {
+ for (const Record *sp : Op->getValueAsListOfDefs("special_params")) {
unsigned Index = sp->getValueAsInt("index");
if (sp->isSubClassOf("IRBuilderAddrParam")) {
AddressArgs.insert(Index);
@@ -1251,7 +1251,7 @@ Result::Ptr EmitterBase::getCodeForDag(DagInit *D, const Result::Scope &Scope,
Args, AddressArgs, IntegerArgs);
} else if (Op->isSubClassOf("IRIntBase")) {
std::vector<const Type *> ParamTypes;
- for (Record *RParam : Op->getValueAsListOfDefs("params"))
+ for (const Record *RParam : Op->getValueAsListOfDefs("params"))
ParamTypes.push_back(getType(RParam, Param));
std::string IntName = std::string(Op->getValueAsString("intname"));
if (Op->getValueAsBit("appendKind"))
@@ -1294,7 +1294,7 @@ Result::Ptr EmitterBase::getCodeForDagArg(DagInit *D, unsigned ArgNum,
return getCodeForDag(DI, Scope, Param);
if (auto *DI = dyn_cast<DefInit>(Arg)) {
- Record *Rec = DI->getDef();
+ const Record *Rec = DI->getDef();
if (Rec->isSubClassOf("Type")) {
const Type *T = getType(Rec, Param);
return std::make_shared<TypeResult>(T);
@@ -1328,7 +1328,8 @@ Result::Ptr EmitterBase::getCodeForArg(unsigned ArgNum, const Type *ArgType,
return V;
}
-ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
+ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, const Record *R,
+ const Type *Param)
: ReturnType(ME.getType(R->getValueAsDef("ret"), Param)) {
// Derive the intrinsic's full name, by taking the name of the
// Tablegen record (or override) and appending the suffix from its
@@ -1346,7 +1347,7 @@ ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
// full name as specified by its 'pnt' member ('polymorphic name type'),
// which indicates how many type suffixes to remove, and any other piece of
// the name that should be removed.
- Record *PolymorphicNameType = R->getValueAsDef("pnt");
+ const Record *PolymorphicNameType = R->getValueAsDef("pnt");
SmallVector<StringRef, 8> NameParts;
StringRef(FullName).split(NameParts, '_');
for (unsigned i = 0, e = PolymorphicNameType->getValueAsInt(
@@ -1393,11 +1394,11 @@ ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
// what values it can take, for Sema checking.
bool Immediate = false;
if (auto TypeDI = dyn_cast<DefInit>(TypeInit)) {
- Record *TypeRec = TypeDI->getDef();
+ const Record *TypeRec = TypeDI->getDef();
if (TypeRec->isSubClassOf("Immediate")) {
Immediate = true;
- Record *Bounds = TypeRec->getValueAsDef("bounds");
+ const Record *Bounds = TypeRec->getValueAsDef("bounds");
ImmediateArg &IA = ImmediateArgs[i];
if (Bounds->isSubClassOf("IB_ConstRange")) {
IA.boundsType = ImmediateArg::BoundsType::ExplicitRange;
@@ -1440,7 +1441,7 @@ ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
// Finally, go through the codegen dag and translate it into a Result object
// (with an arbitrary DAG of depended-on Results hanging off it).
DagInit *CodeDag = R->getValueAsDag("codegen");
- Record *MainOp = cast<DefInit>(CodeDag->getOperator())->getDef();
+ const Record *MainOp = cast<DefInit>(CodeDag->getOperator())->getDef();
if (MainOp->isSubClassOf("CustomCodegen")) {
// Or, if it's the special case of CustomCodegen, just accumulate
// a list of parameters we're going to assign to variables before
@@ -1464,7 +1465,7 @@ ACLEIntrinsic::ACLEIntrinsic(EmitterBase &ME, Record *R, const Type *Param)
}
}
-EmitterBase::EmitterBase(RecordKeeper &Records) {
+EmitterBase::EmitterBase(const RecordKeeper &Records) {
// Construct the whole EmitterBase.
// First, look up all the instances of PrimitiveType. This gives us the list
@@ -1472,13 +1473,13 @@ EmitterBase::EmitterBase(RecordKeeper &Records) {
// collect all the useful ScalarType instances into a big list so that we can
// use it for operations such as 'find the unsigned version of this signed
// integer type'.
- for (Record *R : Records.getAllDerivedDefinitions("PrimitiveType"))
+ for (const Record *R : Records.getAllDerivedDefinitions("PrimitiveType"))
ScalarTypes[std::string(R->getName())] = std::make_unique<ScalarType>(R);
// Now go through the instances of Intrinsic, and for each one, iterate
// through its list of type parameters making an ACLEIntrinsic for each one.
- for (Record *R : Records.getAllDerivedDefinitions("Intrinsic")) {
- for (Record *RParam : R->getValueAsListOfDefs("params")) {
+ for (const Record *R : Records.getAllDerivedDefinitions("Intrinsic")) {
+ for (const Record *RParam : R->getValueAsListOfDefs("params")) {
const Type *Param = getType(RParam, getVoidType());
auto Intrinsic = std::make_unique<ACLEIntrinsic>(*this, R, Param);
ACLEIntrinsics[Intrinsic->fullName()] = std::move(Intrinsic);
@@ -1752,7 +1753,7 @@ void EmitterBase::GroupSemaChecks(
class MveEmitter : public EmitterBase {
public:
- MveEmitter(RecordKeeper &Records) : EmitterBase(Records){};
+ MveEmitter(const RecordKeeper &Records) : EmitterBase(Records) {}
void EmitHeader(raw_ostream &OS) override;
void EmitBuiltinDef(raw_ostream &OS) override;
void EmitBuiltinSema(raw_ostream &OS) override;
@@ -2010,14 +2011,14 @@ class CdeEmitter : public EmitterBase {
std::map<StringRef, FunctionMacro> FunctionMacros;
public:
- CdeEmitter(RecordKeeper &Records);
+ CdeEmitter(const RecordKeeper &Records);
void EmitHeader(raw_ostream &OS) override;
void EmitBuiltinDef(raw_ostream &OS) override;
void EmitBuiltinSema(raw_ostream &OS) override;
};
-CdeEmitter::CdeEmitter(RecordKeeper &Records) : EmitterBase(Records) {
- for (Record *R : Records.getAllDerivedDefinitions("FunctionMacro"))
+CdeEmitter::CdeEmitter(const RecordKeeper &Records) : EmitterBase(Records) {
+ for (const Record *R : Records.getAllDerivedDefinitions("FunctionMacro"))
FunctionMacros.emplace(R->getName(), FunctionMacro(*R));
}
@@ -2179,45 +2180,45 @@ namespace clang {
// MVE
-void EmitMveHeader(RecordKeeper &Records, raw_ostream &OS) {
+void EmitMveHeader(const RecordKeeper &Records, raw_ostream &OS) {
MveEmitter(Records).EmitHeader(OS);
}
-void EmitMveBuiltinDef(RecordKeeper &Records, raw_ostream &OS) {
+void EmitMveBuiltinDef(const RecordKeeper &Records, raw_ostream &OS) {
MveEmitter(Records).EmitBuiltinDef(OS);
}
-void EmitMveBuiltinSema(RecordKeeper &Records, raw_ostream &OS) {
+void EmitMveBuiltinSema(const RecordKeeper &Records, raw_ostream &OS) {
MveEmitter(Records).EmitBuiltinSema(OS);
}
-void EmitMveBuiltinCG(RecordKeeper &Records, raw_ostream &OS) {
+void EmitMveBuiltinCG(const RecordKeeper &Records, raw_ostream &OS) {
MveEmitter(Records).EmitBuiltinCG(OS);
}
-void EmitMveBuiltinAliases(RecordKeeper &Records, raw_ostream &OS) {
+void EmitMveBuiltinAliases(const RecordKeeper &Records, raw_ostream &OS) {
MveEmitter(Records).EmitBuiltinAliases(OS);
}
// CDE
-void EmitCdeHeader(RecordKeeper &Records, raw_ostream &OS) {
+void EmitCdeHeader(const RecordKeeper &Records, raw_ostream &OS) {
CdeEmitter(Records).EmitHeader(OS);
}
-void EmitCdeBuiltinDef(RecordKeeper &Records, raw_ostream &OS) {
+void EmitCdeBuiltinDef(const RecordKeeper &Records, raw_ostream &OS) {
CdeEmitter(Records).EmitBuiltinDef(OS);
}
-void EmitCdeBuiltinSema(RecordKeeper &Records, raw_ostream &OS) {
+void EmitCdeBuiltinSema(const RecordKeeper &Records, raw_ostream &OS) {
CdeEmitter(Records).EmitBuiltinSema(OS);
}
-void EmitCdeBuiltinCG(RecordKeeper &Records, raw_ostream &OS) {
+void EmitCdeBuiltinCG(const RecordKeeper &Records, raw_ostream &OS) {
CdeEmitter(Records).EmitBuiltinCG(OS);
}
-void EmitCdeBuiltinAliases(RecordKeeper &Records, raw_ostream &OS) {
+void EmitCdeBuiltinAliases(const RecordKeeper &Records, raw_ostream &OS) {
CdeEmitter(Records).EmitBuiltinAliases(OS);
}
diff --git a/clang/utils/TableGen/TableGenBackends.h b/clang/utils/TableGen/TableGenBackends.h
index 01d16d2dc3e5f1..fc912b64095f65 100644
--- a/clang/utils/TableGen/TableGenBackends.h
+++ b/clang/utils/TableGen/TableGenBackends.h
@@ -135,22 +135,28 @@ void EmitSmeRangeChecks(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
void EmitSmeStreamingAttrs(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
void EmitSmeBuiltinZAState(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitMveHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitMveBuiltinDef(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitMveBuiltinSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitMveBuiltinCG(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitMveBuiltinAliases(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitMveHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitMveBuiltinDef(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
+void EmitMveBuiltinSema(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
+void EmitMveBuiltinCG(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitMveBuiltinAliases(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
void EmitRVVHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
void EmitRVVBuiltins(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
void EmitRVVBuiltinCG(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
void EmitRVVBuiltinSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitCdeHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitCdeBuiltinDef(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitCdeBuiltinSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitCdeBuiltinCG(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitCdeBuiltinAliases(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitCdeHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitCdeBuiltinDef(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
+void EmitCdeBuiltinSema(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
+void EmitCdeBuiltinCG(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitCdeBuiltinAliases(const llvm::RecordKeeper &Records,
+ llvm::raw_ostream &OS);
void EmitClangAttrDocs(const llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
``````````
</details>
https://github.com/llvm/llvm-project/pull/108500
More information about the cfe-commits
mailing list