Author: John Demme Date: 2020-11-22T16:06:14-08:00 New Revision: 95956c1c9aae7ea21c2b2f7a21e0901d549bd190
URL: https://github.com/llvm/llvm-project/commit/95956c1c9aae7ea21c2b2f7a21e0901d549bd190 DIFF: https://github.com/llvm/llvm-project/commit/95956c1c9aae7ea21c2b2f7a21e0901d549bd190.diff LOG: [MLIR] ODS typedef gen fixes & improvements - Fixes bug 48242 point 3 crash. - Makes the improvments from points 1 & 2. https://bugs.llvm.org/show_bug.cgi?id=48262 ``` def RTLValueType : Type<CPred<"isRTLValueType($_self)">, "Type"> { string cppType = "::mlir::Type"; } ``` Works now, but merely by happenstance. Parameters expects a `TypeParameter` class def or a string representing a c++ type but doesn't enforce it. Reviewed By: lattner Differential Revision: https://reviews.llvm.org/D91939 Added: Modified: mlir/lib/TableGen/TypeDef.cpp mlir/test/mlir-tblgen/typedefs.td mlir/tools/mlir-tblgen/TypeDefGen.cpp Removed: ################################################################################ diff --git a/mlir/lib/TableGen/TypeDef.cpp b/mlir/lib/TableGen/TypeDef.cpp index 86373a481239..aa7f36a3626b 100644 --- a/mlir/lib/TableGen/TypeDef.cpp +++ b/mlir/lib/TableGen/TypeDef.cpp @@ -112,6 +112,8 @@ llvm::Optional<StringRef> TypeParameter::getAllocator() const { if (auto *typeParameter = dyn_cast<llvm::DefInit>(parameterType)) { llvm::RecordVal *code = typeParameter->getDef()->getValue("allocator"); + if (!code) + return llvm::Optional<StringRef>(); if (llvm::CodeInit *ci = dyn_cast<llvm::CodeInit>(code->getValue())) return ci->getValue(); if (isa<llvm::UnsetInit>(code->getValue())) diff --git a/mlir/test/mlir-tblgen/typedefs.td b/mlir/test/mlir-tblgen/typedefs.td index ae459df4934d..6db866a10c8d 100644 --- a/mlir/test/mlir-tblgen/typedefs.td +++ b/mlir/test/mlir-tblgen/typedefs.td @@ -6,6 +6,11 @@ include "mlir/IR/OpBase.td" // DECL: #ifdef GET_TYPEDEF_CLASSES // DECL: #undef GET_TYPEDEF_CLASSES +// DECL: namespace mlir { +// DECL: class DialectAsmParser; +// DECL: class DialectAsmPrinter; +// DECL: } // namespace mlir + // DECL: ::mlir::Type generatedTypeParser(::mlir::MLIRContext* ctxt, ::mlir::DialectAsmParser& parser, ::llvm::StringRef mnenomic); // DECL: ::mlir::LogicalResult generatedTypePrinter(::mlir::Type type, ::mlir::DialectAsmPrinter& printer); @@ -34,6 +39,10 @@ def A_SimpleTypeA : TestType<"SimpleA"> { // DECL: class SimpleAType: public ::mlir::Type } +def RTLValueType : Type<CPred<"isRTLValueType($_self)">, "Type"> { + string cppType = "::mlir::Type"; +} + // A more complex parameterized type def B_CompoundTypeA : TestType<"CompoundA"> { let summary = "A more complex parameterized type"; @@ -44,14 +53,15 @@ def B_CompoundTypeA : TestType<"CompoundA"> { "int":$widthOfSomething, "::mlir::test::SimpleTypeA": $exampleTdType, "SomeCppStruct": $exampleCppType, - ArrayRefParameter<"int", "Matrix dimensions">:$dims + ArrayRefParameter<"int", "Matrix dimensions">:$dims, + RTLValueType:$inner ); let genVerifyInvariantsDecl = 1; // DECL-LABEL: class CompoundAType: public ::mlir::Type -// DECL: static ::mlir::LogicalResult verifyConstructionInvariants(Location loc, int widthOfSomething, ::mlir::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef<int> dims); -// DECL: static ::mlir::Type getChecked(Location loc, int widthOfSomething, ::mlir::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef<int> dims); +// DECL: static ::mlir::LogicalResult verifyConstructionInvariants(::mlir::Location loc, int widthOfSomething, ::mlir::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef<int> dims, ::mlir::Type inner); +// DECL: static ::mlir::Type getChecked(::mlir::Location loc, 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 ::mlir::Type parse(::mlir::MLIRContext* ctxt, ::mlir::DialectAsmParser& parser); // DECL: void print(::mlir::DialectAsmPrinter& printer) const; diff --git a/mlir/tools/mlir-tblgen/TypeDefGen.cpp b/mlir/tools/mlir-tblgen/TypeDefGen.cpp index 4473f629f3f1..0990a5afb884 100644 --- a/mlir/tools/mlir-tblgen/TypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/TypeDefGen.cpp @@ -133,6 +133,15 @@ class TypeParamCommaFormatter : public llvm::detail::format_adapter { // GEN: TypeDef declarations //===----------------------------------------------------------------------===// +/// Print this above all the other declarations. Contains type declarations used +/// later on. +static const char *const typeDefDeclHeader = R"( +namespace mlir { +class DialectAsmParser; +class DialectAsmPrinter; +} // namespace mlir +)"; + /// The code block for the start of a typeDef class declaration -- singleton /// case. /// @@ -174,8 +183,8 @@ static const char *const typeDefParsePrint = R"( /// /// {0}: List of parameters, parameters style. static const char *const typeDefDeclVerifyStr = R"( - static ::mlir::LogicalResult verifyConstructionInvariants(Location loc{0}); - static ::mlir::Type getChecked(Location loc{0}); + static ::mlir::LogicalResult verifyConstructionInvariants(::mlir::Location loc{0}); + static ::mlir::Type getChecked(::mlir::Location loc{0}); )"; /// Generate the declaration for the given typeDef class. @@ -239,6 +248,10 @@ static bool emitTypeDefDecls(const llvm::RecordKeeper &recordKeeper, findAllTypeDefs(recordKeeper, typeDefs); IfDefScope scope("GET_TYPEDEF_CLASSES", os); + + // Output the common "header". + os << typeDefDeclHeader; + if (typeDefs.size() > 0) { NamespaceEmitter nsEmitter(os, typeDefs.begin()->getDialect()); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits