diff --git a/mlir/include/mlir/TableGen/OpClass.h b/mlir/include/mlir/TableGen/OpClass.h --- a/mlir/include/mlir/TableGen/OpClass.h +++ b/mlir/include/mlir/TableGen/OpClass.h @@ -238,6 +238,8 @@ MP_Constructor = 0x2, MP_Private = 0x4, MP_Declaration = 0x8, + MP_Inline = 0x10, + MP_Constexpr = 0x20 | MP_Inline, MP_StaticDeclaration = MP_Static | MP_Declaration, }; @@ -260,6 +262,9 @@ // Returns true if this is a private method. bool isPrivate() const { return properties & MP_Private; } + // Returns true if this is an inline method. + bool isInline() const { return properties & MP_Inline; } + // Returns the name of this method. StringRef getName() const { return methodSignature.getName(); } diff --git a/mlir/lib/TableGen/OpClass.cpp b/mlir/lib/TableGen/OpClass.cpp --- a/mlir/lib/TableGen/OpClass.cpp +++ b/mlir/lib/TableGen/OpClass.cpp @@ -201,14 +201,25 @@ os.indent(2); if (isStatic()) os << "static "; + if (properties & MP_Constexpr) + os << "constexpr "; methodSignature.writeDeclTo(os); - os << ";"; + if (!isInline()) + os << ";"; + else { + os << " {\n"; + methodBody.writeTo(os); + os << "}"; + } } void OpMethod::writeDefTo(raw_ostream &os, StringRef namePrefix) const { // Do not write definition if the method is decl only. if (properties & MP_Declaration) return; + // Do not generate separate definition for inline method + if (isInline()) + return; methodSignature.writeDefTo(os, namePrefix); os << " {\n"; methodBody.writeTo(os); diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td --- a/mlir/test/mlir-tblgen/op-decl-and-defs.td +++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td @@ -71,7 +71,9 @@ // CHECK: public: // CHECK: using Op::Op; // CHECK: using Adaptor = AOpAdaptor; -// CHECK: static ::llvm::StringRef getOperationName(); +// CHECK: static constexpr ::llvm::StringLiteral getOperationName() { +// CHECK: return ::llvm::StringLiteral("test.a_op"); +// CHECK: } // CHECK: ::mlir::Operation::operand_range getODSOperands(unsigned index); // CHECK: ::mlir::Value a(); // CHECK: ::mlir::Operation::operand_range b(); diff --git a/mlir/test/mlir-tblgen/typedefs.td b/mlir/test/mlir-tblgen/typedefs.td --- a/mlir/test/mlir-tblgen/typedefs.td +++ b/mlir/test/mlir-tblgen/typedefs.td @@ -59,7 +59,9 @@ // DECL-LABEL: class CompoundAType : public ::mlir::Type // DECL: static CompoundAType getChecked(llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::MLIRContext *context, int widthOfSomething, ::mlir::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef dims, ::mlir::Type inner); // DECL: static ::mlir::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int widthOfSomething, ::mlir::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef dims, ::mlir::Type inner); -// DECL: static ::llvm::StringRef getMnemonic() { return "cmpnd_a"; } +// DECL: static constexpr ::llvm::StringLiteral getMnemonic() { +// DECL: return ::llvm::StringLiteral("cmpnd_a"); +// DECL: } // DECL: static ::mlir::Type parse(::mlir::MLIRContext *context, // DECL-NEXT: ::mlir::DialectAsmParser &parser); // DECL: void print(::mlir::DialectAsmPrinter &printer) const; @@ -77,7 +79,9 @@ ); // DECL-LABEL: class IndexType : public ::mlir::Type -// DECL: static ::llvm::StringRef getMnemonic() { return "index"; } +// DECL: static constexpr ::llvm::StringLiteral getMnemonic() { +// DECL: return ::llvm::StringLiteral("index"); +// DECL: } // DECL: static ::mlir::Type parse(::mlir::MLIRContext *context, // DECL-NEXT: ::mlir::DialectAsmParser &parser); // DECL: void print(::mlir::DialectAsmPrinter &printer) const; diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp --- a/mlir/tools/mlir-tblgen/DialectGen.cpp +++ b/mlir/tools/mlir-tblgen/DialectGen.cpp @@ -75,7 +75,9 @@ void initialize(); friend class ::mlir::MLIRContext; public: - static ::llvm::StringRef getDialectNamespace() { return "{1}"; } + static constexpr ::llvm::StringLiteral getDialectNamespace() { + return ::llvm::StringLiteral("{1}"); + } )"; /// Registration for a single dependent dialect: to be inserted in the ctor diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -2181,8 +2181,10 @@ void OpEmitter::genOpNameGetter() { auto *method = opClass.addMethodAndPrune( - "::llvm::StringRef", "getOperationName", OpMethod::MP_Static); - method->body() << " return \"" << op.getOperationName() << "\";\n"; + "::llvm::StringLiteral", "getOperationName", + OpMethod::Property(OpMethod::MP_Static | OpMethod::MP_Constexpr)); + method->body() << " return ::llvm::StringLiteral(\"" << op.getOperationName() + << "\");"; } void OpEmitter::genOpAsmInterface() { diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp --- a/mlir/tools/mlir-tblgen/PassGen.cpp +++ b/mlir/tools/mlir-tblgen/PassGen.cpp @@ -45,13 +45,21 @@ template class {0}Base : public {1} { public: + using Base = {0}Base; + {0}Base() : {1}(::mlir::TypeID::get()) {{} {0}Base(const {0}Base &) : {1}(::mlir::TypeID::get()) {{} /// Returns the command-line argument attached to this pass. + static constexpr ::llvm::StringLiteral getArgumentName() { + return ::llvm::StringLiteral("{2}"); + } ::llvm::StringRef getArgument() const override { return "{2}"; } /// Returns the derived pass name. + static constexpr ::llvm::StringLiteral getPassName() { + return ::llvm::StringLiteral("{0}"); + } ::llvm::StringRef getName() const override { return "{0}"; } /// Support isa/dyn_cast functionality for the derived pass class. diff --git a/mlir/tools/mlir-tblgen/TypeDefGen.cpp b/mlir/tools/mlir-tblgen/TypeDefGen.cpp --- a/mlir/tools/mlir-tblgen/TypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/TypeDefGen.cpp @@ -277,8 +277,9 @@ // Emit the mnenomic, if specified. if (auto mnenomic = typeDef.getMnemonic()) { - os << " static ::llvm::StringRef getMnemonic() { return \"" << mnenomic - << "\"; }\n"; + os << " static constexpr ::llvm::StringLiteral getMnemonic() {\n" + << " return ::llvm::StringLiteral(\"" << mnenomic << "\");\n" + << " }\n"; // If mnemonic specified, emit print/parse declarations. if (typeDef.getParserCode() || typeDef.getPrinterCode() || !params.empty())