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