MLIR  20.0.0git
MLProgramDialect.cpp
Go to the documentation of this file.
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 
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 {
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 {
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 }
static bool isLegalToInline(InlinerInterface &interface, Region *src, Region *insertRegion, bool shouldCloneInlinedRegion, IRMapping &valueMapping)
Utility to check that all of the operations within 'src' can be inlined.
The possible results of an alias query.
Definition: AliasAnalysis.h:26
@ NoAlias
The two locations do not alias at all.
Definition: AliasAnalysis.h:34
Attributes are known-constant values of operations.
Definition: Attributes.h:25
This is the interface that must be implemented by the dialects of operations to be inlined.
Definition: InliningUtils.h:44
DialectInlinerInterface(Dialect *dialect)
Definition: InliningUtils.h:46
This is a utility class for mapping one set of IR entities to another.
Definition: IRMapping.h:26
OpAsmDialectInterface(Dialect *dialect)
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
Include the generated interface declarations.