From 140b28ec129f4f0906150f04b702978f08d7d87e Mon Sep 17 00:00:00 2001 From: River Riddle Date: Thu, 22 Aug 2019 11:31:01 -0700 Subject: [PATCH] NFC: Avoid reconstructing the OpInterface methods. PiperOrigin-RevId: 264881293 --- mlir/tools/mlir-tblgen/OpInterfacesGen.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp index 837d5a5..d3d4482 100644 --- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp +++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp @@ -123,9 +123,7 @@ static void emitInterfaceDef(const Record &interfaceDef, raw_ostream &os) { StringRef interfaceName = interface.getName(); // Insert the method definitions. - auto *listInit = dyn_cast(interfaceDef.getValueInit("methods")); - for (Init *init : listInit->getValues()) { - OpInterfaceMethod method(cast(init)->getDef()); + for (auto &method : interface.getMethods()) { os << method.getReturnType() << " " << interfaceName << "::"; emitMethodNameAndArgs(method, os, /*addOperationArg=*/false); @@ -149,17 +147,13 @@ static bool emitInterfaceDefs(const RecordKeeper &recordKeeper, 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(interfaceDef.getValueInit("methods")); - for (Init *init : listInit->getValues()) { - OpInterfaceMethod method(cast(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 @@ static void emitConceptDecl(const Record &interfaceDef, raw_ostream &os) { os << " };\n"; } -static void emitModelDecl(const Record &interfaceDef, raw_ostream &os) { +static void emitModelDecl(OpInterface &interface, raw_ostream &os) { os << " template\n"; os << " class Model : public Concept {\npublic:\n"; // Insert each of the virtual method overrides. - auto *listInit = dyn_cast(interfaceDef.getValueInit("methods")); - for (Init *init : listInit->getValues()) { - OpInterfaceMethod method(cast(init)->getDef()); + for (auto &method : interface.getMethods()) { os << " " << method.getReturnType() << " "; emitMethodNameAndArgs(method, os, /*addOperationArg=*/!method.isStatic()); os << " final {\n"; @@ -211,8 +203,8 @@ static void emitInterfaceDecl(const Record &interfaceDef, raw_ostream &os) { // 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. -- 2.7.4