xref: /llvm-project/flang/lib/Optimizer/Builder/Complex.cpp (revision c4204c0b29a6721267b1bcbaeedd7b1118e42396)
1 //===-- Complex.cpp -------------------------------------------------------===//
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 "flang/Optimizer/Builder/Complex.h"
10 
11 //===----------------------------------------------------------------------===//
12 // Complex Factory implementation
13 //===----------------------------------------------------------------------===//
14 
15 mlir::Type
16 fir::factory::Complex::getComplexPartType(mlir::Type complexType) const {
17   return mlir::cast<mlir::ComplexType>(complexType).getElementType();
18 }
19 
20 mlir::Type fir::factory::Complex::getComplexPartType(mlir::Value cplx) const {
21   return getComplexPartType(cplx.getType());
22 }
23 
24 mlir::Value fir::factory::Complex::createComplex(mlir::Type cplxTy,
25                                                  mlir::Value real,
26                                                  mlir::Value imag) {
27   mlir::Value und = builder.create<fir::UndefOp>(loc, cplxTy);
28   return insert<Part::Imag>(insert<Part::Real>(und, real), imag);
29 }
30 
31 mlir::Value fir::factory::Complex::createComplex(mlir::Value real,
32                                                  mlir::Value imag) {
33   assert(real.getType() == imag.getType() && "part types must match");
34   mlir::Type cplxTy = mlir::ComplexType::get(real.getType());
35   return createComplex(cplxTy, real, imag);
36 }
37