Changeset View
Changeset View
Standalone View
Standalone View
mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | static void emitModelDecl(OpInterface &interface, raw_ostream &os) { | ||||
} | } | ||||
os << " };\n"; | os << " };\n"; | ||||
} | } | ||||
static void emitTraitDecl(OpInterface &interface, raw_ostream &os, | static void emitTraitDecl(OpInterface &interface, raw_ostream &os, | ||||
StringRef interfaceName, | StringRef interfaceName, | ||||
StringRef interfaceTraitsName) { | StringRef interfaceTraitsName) { | ||||
os << " template <typename ConcreteOp>\n " | os << " template <typename ConcreteOp>\n " | ||||
<< llvm::formatv("struct Trait : public OpInterface<{0}," | << llvm::formatv("struct {0}Trait : public OpInterface<{0}," | ||||
" detail::{1}>::Trait<ConcreteOp> {{\n", | " detail::{1}>::Trait<ConcreteOp> {{\n", | ||||
interfaceName, interfaceTraitsName); | interfaceName, interfaceTraitsName); | ||||
// Insert the default implementation for any methods. | // Insert the default implementation for any methods. | ||||
for (auto &method : interface.getMethods()) { | for (auto &method : interface.getMethods()) { | ||||
// Flag interface methods named verifyTrait. | // Flag interface methods named verifyTrait. | ||||
if (method.getName() == "verifyTrait") | if (method.getName() == "verifyTrait") | ||||
PrintFatalError( | PrintFatalError( | ||||
formatv("'verifyTrait' method cannot be specified as interface " | formatv("'verifyTrait' method cannot be specified as interface " | ||||
"method for '{0}'; set 'verify' on OpInterfaceTrait instead", | "method for '{0}'; set 'verify' on OpInterfaceTrait instead", | ||||
interfaceName)); | interfaceName)); | ||||
auto defaultImpl = method.getDefaultImplementation(); | auto defaultImpl = method.getDefaultImplementation(); | ||||
if (!defaultImpl) | if (!defaultImpl) | ||||
continue; | continue; | ||||
os << " " << (method.isStatic() ? "static " : "") << method.getReturnType() | os << " " << (method.isStatic() ? "static " : "") << method.getReturnType() | ||||
<< " "; | << " "; | ||||
emitMethodNameAndArgs(method, os, /*addOperationArg=*/false); | emitMethodNameAndArgs(method, os, /*addOperationArg=*/false); | ||||
os << " {\n" << defaultImpl.getValue() << " }\n"; | os << " {\n" << defaultImpl.getValue() << " }\n"; | ||||
} | } | ||||
tblgen::FmtContext traitCtx; | tblgen::FmtContext traitCtx; | ||||
traitCtx.withOp("op"); | traitCtx.withOp("op"); | ||||
if (auto verify = interface.getVerify()) { | if (auto verify = interface.getVerify()) { | ||||
os << " static LogicalResult verifyTrait(Operation* op) {\n" | os << " static LogicalResult verifyTrait(Operation* op) {\n" | ||||
<< std::string(tblgen::tgfmt(*verify, &traitCtx)) << "\n }\n"; | << std::string(tblgen::tgfmt(*verify, &traitCtx)) << "\n }\n"; | ||||
} | } | ||||
if (auto extraTraitDecls = interface.getExtraTraitClassDeclaration()) | if (auto extraTraitDecls = interface.getExtraTraitClassDeclaration()) | ||||
os << extraTraitDecls << "\n"; | os << extraTraitDecls << "\n"; | ||||
os << " };\n"; | os << " };\n"; | ||||
// Emit a utility using directive for the trait class. | |||||
os << " template <typename ConcreteOp>\n " | |||||
<< llvm::formatv("using Trait = {0}Trait<ConcreteOp>;\n", interfaceName); | |||||
} | } | ||||
static void emitInterfaceDecl(OpInterface &interface, raw_ostream &os) { | static void emitInterfaceDecl(OpInterface &interface, raw_ostream &os) { | ||||
StringRef interfaceName = interface.getName(); | StringRef interfaceName = interface.getName(); | ||||
auto interfaceTraitsName = (interfaceName + "InterfaceTraits").str(); | auto interfaceTraitsName = (interfaceName + "InterfaceTraits").str(); | ||||
// Emit the traits struct containing the concept and model declarations. | // Emit the traits struct containing the concept and model declarations. | ||||
os << "namespace detail {\n" | os << "namespace detail {\n" | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |