1 //===- ComplexDialect.cpp - MLIR Complex Dialect --------------------------===//
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/Arithmetic/IR/Arithmetic.h"
10 #include "mlir/Dialect/Complex/IR/Complex.h"
11 #include "mlir/Dialect/StandardOps/IR/Ops.h"
12 
13 using namespace mlir;
14 
15 #include "mlir/Dialect/Complex/IR/ComplexOpsDialect.cpp.inc"
16 
17 void complex::ComplexDialect::initialize() {
18   addOperations<
19 #define GET_OP_LIST
20 #include "mlir/Dialect/Complex/IR/ComplexOps.cpp.inc"
21       >();
22 }
23 
24 Operation *complex::ComplexDialect::materializeConstant(OpBuilder &builder,
25                                                         Attribute value,
26                                                         Type type,
27                                                         Location loc) {
28   // TODO complex.constant
29   if (type.isa<ComplexType>())
30     return builder.create<ConstantOp>(loc, type, value);
31   if (arith::ConstantOp::isBuildableWith(value, type))
32     return builder.create<arith::ConstantOp>(loc, type, value);
33   return nullptr;
34 }
35