MP_Constructor = 0x2,
MP_Private = 0x4,
MP_Declaration = 0x8,
+ MP_Inline = 0x10,
+ MP_Constexpr = 0x20 | MP_Inline,
MP_StaticDeclaration = MP_Static | MP_Declaration,
};
// 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(); }
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);
// 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();
// 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<int> 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<int> 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;
);
// 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;
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
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() {
template <typename DerivedT>
class {0}Base : public {1} {
public:
+ using Base = {0}Base;
+
{0}Base() : {1}(::mlir::TypeID::get<DerivedT>()) {{}
{0}Base(const {0}Base &) : {1}(::mlir::TypeID::get<DerivedT>()) {{}
/// 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.
// 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())