| // Copyright 2021 The IREE Authors | |
| // | |
| // 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 "iree-dialects/Dialect/IREE/IREEOps.h" | |
| #include "iree-dialects/Dialect/IREE/IREEDialect.h" | |
| #include "mlir/IR/Builders.h" | |
| #include "mlir/IR/BuiltinTypes.h" | |
| #include "mlir/IR/OpImplementation.h" | |
| #include "mlir/IR/TypeUtilities.h" | |
| using namespace mlir; | |
| using namespace mlir::iree; | |
| //===----------------------------------------------------------------------===// | |
| // custom<SymbolVisibility>($sym_visibility) | |
| //===----------------------------------------------------------------------===// | |
| // some.op custom<SymbolVisibility>($sym_visibility) $sym_name | |
| // -> | |
| // some.op @foo | |
| // some.op private @foo | |
| static ParseResult parseSymbolVisibility(OpAsmParser &parser, | |
| StringAttr &symVisibilityAttr) { | |
| StringRef symVisibility; | |
| parser.parseOptionalKeyword(&symVisibility, {"public", "private", "nested"}); | |
| if (!symVisibility.empty()) { | |
| symVisibilityAttr = parser.getBuilder().getStringAttr(symVisibility); | |
| } | |
| return success(); | |
| } | |
| static void printSymbolVisibility(OpAsmPrinter &p, Operation *op, | |
| StringAttr symVisibilityAttr) { | |
| if (!symVisibilityAttr) { | |
| p << "public"; | |
| } else { | |
| p << symVisibilityAttr.getValue(); | |
| } | |
| } | |
| //===----------------------------------------------------------------------===// | |
| // custom<TypeOrAttr>($type, $attr) | |
| //===----------------------------------------------------------------------===// | |
| // some.op custom<TypeOrAttr>($type, $attr) | |
| // -> | |
| // some.op : i32 | |
| // some.op = 42 : i32 | |
| // some.op : i32 = 42 : index | |
| static ParseResult parseTypeOrAttr(OpAsmParser &parser, TypeAttr &typeAttr, | |
| Attribute &attr) { | |
| if (succeeded(parser.parseOptionalEqual())) { | |
| if (failed(parser.parseAttribute(attr))) { | |
| return parser.emitError(parser.getCurrentLocation()) | |
| << "expected attribute"; | |
| } | |
| typeAttr = TypeAttr::get(attr.getType()); | |
| return success(); | |
| } | |
| Type type; | |
| if (failed(parser.parseColonType(type))) { | |
| return parser.emitError(parser.getCurrentLocation()) << "expected type"; | |
| } | |
| typeAttr = TypeAttr::get(type); | |
| if (succeeded(parser.parseOptionalEqual())) { | |
| if (failed(parser.parseAttribute(attr))) { | |
| return parser.emitError(parser.getCurrentLocation()) | |
| << "expected attribute"; | |
| } | |
| } | |
| return success(); | |
| } | |
| static void printTypeOrAttr(OpAsmPrinter &p, Operation *op, TypeAttr type, | |
| Attribute attr) { | |
| if (!attr || attr.getType() != type.getValue()) { | |
| p << " : "; | |
| p.printAttribute(type); | |
| } | |
| if (attr) { | |
| p << " = "; | |
| p.printAttribute(attr); | |
| } | |
| } | |
| #define GET_OP_CLASSES | |
| #include "iree-dialects/Dialect/IREE/IREEOps.cpp.inc" |