diff --git a/mlir/examples/standalone/include/Standalone/StandaloneDialect.td b/mlir/examples/standalone/include/Standalone/StandaloneDialect.td --- a/mlir/examples/standalone/include/Standalone/StandaloneDialect.td +++ b/mlir/examples/standalone/include/Standalone/StandaloneDialect.td @@ -25,6 +25,10 @@ }]; let cppNamespace = "::mlir::standalone"; + let useDefaultTypePrinterParser = 1; + let extraClassDeclaration = [{ + void registerTypes(); + }]; } //===----------------------------------------------------------------------===// diff --git a/mlir/examples/standalone/include/Standalone/StandaloneOps.td b/mlir/examples/standalone/include/Standalone/StandaloneOps.td --- a/mlir/examples/standalone/include/Standalone/StandaloneOps.td +++ b/mlir/examples/standalone/include/Standalone/StandaloneOps.td @@ -9,7 +9,7 @@ #ifndef STANDALONE_OPS #define STANDALONE_OPS -include "Standalone/StandaloneDialect.td" +include "Standalone/StandaloneTypes.td" include "mlir/Interfaces/InferTypeOpInterface.td" include "mlir/Interfaces/SideEffectInterfaces.td" diff --git a/mlir/examples/standalone/include/Standalone/StandaloneTypes.h b/mlir/examples/standalone/include/Standalone/StandaloneTypes.h new file mode 100644 --- /dev/null +++ b/mlir/examples/standalone/include/Standalone/StandaloneTypes.h @@ -0,0 +1,17 @@ +//===- StandaloneTypes.h - Standalone dialect types -------------*- C++ -*-===// +// +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef STANDALONE_STANDALONETYPES_H +#define STANDALONE_STANDALONETYPES_H + +#include "mlir/IR/BuiltinTypes.h" + +#define GET_TYPEDEF_CLASSES +#include "Standalone/StandaloneOpsTypes.h.inc" + +#endif // STANDALONE_STANDALONETYPES_H diff --git a/mlir/examples/standalone/include/Standalone/StandaloneTypes.td b/mlir/examples/standalone/include/Standalone/StandaloneTypes.td new file mode 100644 --- /dev/null +++ b/mlir/examples/standalone/include/Standalone/StandaloneTypes.td @@ -0,0 +1,31 @@ +//===- StandaloneTypes.td - Standalone dialect types -------*- tablegen -*-===// +// +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef STANDALONE_TYPES +#define STANDALONE_TYPES + +include "mlir/IR/AttrTypeBase.td" +include "Standalone/StandaloneDialect.td" + +//===----------------------------------------------------------------------===// +// Standalone type definitions +//===----------------------------------------------------------------------===// + +class Standalone_Type traits = []> + : TypeDef { + let mnemonic = typeMnemonic; +} + +def Standalone_CustomType : Standalone_Type<"Custom", "custom"> { + let summary = "Standalone custom type"; + let description = "Custom type in standalone dialect"; + let parameters = (ins StringRefParameter<"the custom value">:$value); + let assemblyFormat = "`<` $value `>`"; +} + +#endif // STANDALONE_TYPES diff --git a/mlir/examples/standalone/lib/Standalone/CMakeLists.txt b/mlir/examples/standalone/lib/Standalone/CMakeLists.txt --- a/mlir/examples/standalone/lib/Standalone/CMakeLists.txt +++ b/mlir/examples/standalone/lib/Standalone/CMakeLists.txt @@ -1,4 +1,5 @@ add_mlir_dialect_library(MLIRStandalone + StandaloneTypes.cpp StandaloneDialect.cpp StandaloneOps.cpp diff --git a/mlir/examples/standalone/lib/Standalone/StandaloneDialect.cpp b/mlir/examples/standalone/lib/Standalone/StandaloneDialect.cpp --- a/mlir/examples/standalone/lib/Standalone/StandaloneDialect.cpp +++ b/mlir/examples/standalone/lib/Standalone/StandaloneDialect.cpp @@ -8,6 +8,7 @@ #include "Standalone/StandaloneDialect.h" #include "Standalone/StandaloneOps.h" +#include "Standalone/StandaloneTypes.h" using namespace mlir; using namespace mlir::standalone; @@ -23,4 +24,5 @@ #define GET_OP_LIST #include "Standalone/StandaloneOps.cpp.inc" >(); + registerTypes(); } diff --git a/mlir/examples/standalone/lib/Standalone/StandaloneTypes.cpp b/mlir/examples/standalone/lib/Standalone/StandaloneTypes.cpp new file mode 100644 --- /dev/null +++ b/mlir/examples/standalone/lib/Standalone/StandaloneTypes.cpp @@ -0,0 +1,26 @@ +//===- StandaloneTypes.cpp - Standalone dialect types -----------*- C++ -*-===// +// +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "Standalone/StandaloneTypes.h" + +#include "Standalone/StandaloneDialect.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/DialectImplementation.h" +#include "llvm/ADT/TypeSwitch.h" + +using namespace mlir::standalone; + +#define GET_TYPEDEF_CLASSES +#include "Standalone/StandaloneOpsTypes.cpp.inc" + +void StandaloneDialect::registerTypes() { + addTypes< +#define GET_TYPEDEF_LIST +#include "Standalone/StandaloneOpsTypes.cpp.inc" + >(); +} diff --git a/mlir/examples/standalone/test/Standalone/dummy.mlir b/mlir/examples/standalone/test/Standalone/dummy.mlir --- a/mlir/examples/standalone/test/Standalone/dummy.mlir +++ b/mlir/examples/standalone/test/Standalone/dummy.mlir @@ -8,4 +8,9 @@ %res = standalone.foo %0 : i32 return } + + // CHECK-LABEL: func @standalone_types(%arg0: !standalone.custom<"10">) + func.func @standalone_types(%arg0: !standalone.custom<"10">) { + return + } }