Files
clang-p2996/mlir/test/lib/Dialect/Test/TestDialect.td
Markus Böck b121c26674 [mlir] Add helper method to print and parse cyclic attributes and types (#65210)
Printing cyclic attributes and types currently has no first-class
support within the AsmPrinter and AsmParser. The workaround for this
issue used in all mutable attributes and types upstream has been to
create a `thread_local static SetVector` keeping track of currently
parsed and printed attributes.

This solution is not ideal readability wise due to the use of globals
and keeping track of state. Worst of all, this pattern had to be
reimplemented for every mutable attribute and type.

This patch therefore adds support for this pattern in `AsmPrinter` and
`AsmParser` replacing the use of this pattern. By calling
`tryStartCyclingPrint/Parse`, the mutable attribute or type are
registered in an internal stack. All subsequent calls to the function
with the same attribute or type will lead to returning failure. This way
the nesting can be detected and a short form printed or parsed instead.
Through the resetter returned by the call, the cyclic printing or
parsing region automatically ends on return.
2023-09-04 18:19:18 +02:00

53 lines
1.7 KiB
TableGen

//===-- TestDialect.td - Test dialect definition -----------*- tablegen -*-===//
//
// Part of the LLVM Project, 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 TEST_DIALECT
#define TEST_DIALECT
include "mlir/IR/OpBase.td"
def Test_Dialect : Dialect {
let name = "test";
let cppNamespace = "::test";
let hasCanonicalizer = 1;
let hasConstantMaterializer = 1;
let hasOperationAttrVerify = 1;
let hasRegionArgAttrVerify = 1;
let hasRegionResultAttrVerify = 1;
let hasOperationInterfaceFallback = 1;
let hasNonDefaultDestructor = 1;
let useDefaultTypePrinterParser = 0;
let useDefaultAttributePrinterParser = 1;
let isExtensible = 1;
let dependentDialects = ["::mlir::DLTIDialect"];
let extraClassDeclaration = [{
void registerAttributes();
void registerInterfaces();
void registerTypes();
void registerOpsSyntax();
// Provides a custom printing/parsing for some operations.
::std::optional<ParseOpHook>
getParseOperationHook(::llvm::StringRef opName) const override;
::llvm::unique_function<void(::mlir::Operation *,
::mlir::OpAsmPrinter &printer)>
getOperationPrinter(::mlir::Operation *op) const override;
::mlir::Type parseType(::mlir::DialectAsmParser &parser) const override;
void printType(::mlir::Type type,
::mlir::DialectAsmPrinter &printer) const override;
private:
// Storage for a custom fallback interface.
void *fallbackEffectOpInterfaces;
}];
}
#endif // TEST_DIALECT