forked from OSchip/llvm-project
[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
This commit is contained in:
parent
15a3ae1ab1
commit
95956c1c9a
|
@ -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()))
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -133,6 +133,15 @@ private:
|
|||
// 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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue