1 | //===- MLProgramDialect.cpp - MLProgram dialect implementation ------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "mlir/Dialect/MLProgram/IR/MLProgram.h" |
10 | #include "mlir/IR/DialectImplementation.h" |
11 | #include "mlir/Transforms/InliningUtils.h" |
12 | #include "llvm/ADT/TypeSwitch.h" |
13 | |
14 | using namespace mlir; |
15 | using namespace mlir::ml_program; |
16 | |
17 | //===----------------------------------------------------------------------===// |
18 | /// Tablegen Definitions |
19 | //===----------------------------------------------------------------------===// |
20 | |
21 | #include "mlir/Dialect/MLProgram/IR/MLProgramOpsDialect.cpp.inc" |
22 | #define GET_ATTRDEF_CLASSES |
23 | #include "mlir/Dialect/MLProgram/IR/MLProgramAttributes.cpp.inc" |
24 | #define GET_TYPEDEF_CLASSES |
25 | #include "mlir/Dialect/MLProgram/IR/MLProgramTypes.cpp.inc" |
26 | |
27 | namespace { |
28 | |
29 | struct MLProgramInlinerInterface : public DialectInlinerInterface { |
30 | using DialectInlinerInterface::DialectInlinerInterface; |
31 | |
32 | bool isLegalToInline(Operation *, Region *, bool, |
33 | IRMapping &) const override { |
34 | // We have no specific opinion on whether ops defined in this dialect should |
35 | // be inlined. |
36 | return true; |
37 | } |
38 | }; |
39 | |
40 | struct MLProgramOpAsmDialectInterface : public OpAsmDialectInterface { |
41 | using OpAsmDialectInterface::OpAsmDialectInterface; |
42 | |
43 | AliasResult getAlias(Attribute attr, raw_ostream &os) const override { |
44 | if (llvm::isa<ExternAttr>(attr)) { |
45 | os << "extern" ; |
46 | return AliasResult::OverridableAlias; |
47 | } |
48 | return AliasResult::NoAlias; |
49 | } |
50 | }; |
51 | } // namespace |
52 | |
53 | void ml_program::MLProgramDialect::initialize() { |
54 | #define GET_ATTRDEF_LIST |
55 | addAttributes< |
56 | #include "mlir/Dialect/MLProgram/IR/MLProgramAttributes.cpp.inc" |
57 | >(); |
58 | |
59 | #define GET_TYPEDEF_LIST |
60 | addTypes< |
61 | #include "mlir/Dialect/MLProgram/IR/MLProgramTypes.cpp.inc" |
62 | >(); |
63 | |
64 | addOperations< |
65 | #define GET_OP_LIST |
66 | #include "mlir/Dialect/MLProgram/IR/MLProgramOps.cpp.inc" |
67 | >(); |
68 | |
69 | addInterfaces<MLProgramInlinerInterface, MLProgramOpAsmDialectInterface>(); |
70 | } |
71 | |