NFC: Avoid reconstructing the OpInterface methods.
PiperOrigin-RevId: 264881293
diff --git a/tools/mlir-tblgen/OpInterfacesGen.cpp b/tools/mlir-tblgen/OpInterfacesGen.cpp
index 837d5a5..d3d4482 100644
--- a/tools/mlir-tblgen/OpInterfacesGen.cpp
+++ b/tools/mlir-tblgen/OpInterfacesGen.cpp
@@ -123,9 +123,7 @@
StringRef interfaceName = interface.getName();
// Insert the method definitions.
- auto *listInit = dyn_cast<ListInit>(interfaceDef.getValueInit("methods"));
- for (Init *init : listInit->getValues()) {
- OpInterfaceMethod method(cast<DefInit>(init)->getDef());
+ for (auto &method : interface.getMethods()) {
os << method.getReturnType() << " " << interfaceName << "::";
emitMethodNameAndArgs(method, os, /*addOperationArg=*/false);
@@ -149,17 +147,13 @@
return false;
}
-static void emitConceptDecl(const Record &interfaceDef, raw_ostream &os) {
+static void emitConceptDecl(OpInterface &interface, raw_ostream &os) {
os << " class Concept {\n"
<< " public:\n"
<< " virtual ~Concept() = default;\n";
- // Insert each of the virtual methods.
- auto *listInit = dyn_cast<ListInit>(interfaceDef.getValueInit("methods"));
- for (Init *init : listInit->getValues()) {
- OpInterfaceMethod method(cast<DefInit>(init)->getDef());
-
- // In the concept, all methods are pure virtual.
+ // Insert each of the pure virtual concept methods.
+ for (auto &method : interface.getMethods()) {
os << " virtual " << method.getReturnType() << " ";
emitMethodNameAndArgs(method, os, /*addOperationArg=*/!method.isStatic());
os << " = 0;\n";
@@ -167,14 +161,12 @@
os << " };\n";
}
-static void emitModelDecl(const Record &interfaceDef, raw_ostream &os) {
+static void emitModelDecl(OpInterface &interface, raw_ostream &os) {
os << " template<typename ConcreteOp>\n";
os << " class Model : public Concept {\npublic:\n";
// Insert each of the virtual method overrides.
- auto *listInit = dyn_cast<ListInit>(interfaceDef.getValueInit("methods"));
- for (Init *init : listInit->getValues()) {
- OpInterfaceMethod method(cast<DefInit>(init)->getDef());
+ for (auto &method : interface.getMethods()) {
os << " " << method.getReturnType() << " ";
emitMethodNameAndArgs(method, os, /*addOperationArg=*/!method.isStatic());
os << " final {\n";
@@ -211,8 +203,8 @@
// Emit the traits struct containing the concept and model declarations.
os << "namespace detail {\n"
<< "struct " << interfaceTraitsName << " {\n";
- emitConceptDecl(interfaceDef, os);
- emitModelDecl(interfaceDef, os);
+ emitConceptDecl(interface, os);
+ emitModelDecl(interface, os);
os << "};\n} // end namespace detail\n";
// Emit the main interface class declaration.