aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Optimizer/Builder/Complex.cpp
blob: 61de9880774ac040fbbd95062eea90b0a908ce98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//===-- Complex.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "flang/Optimizer/Builder/Complex.h"

//===----------------------------------------------------------------------===//
// Complex Factory implementation
//===----------------------------------------------------------------------===//

mlir::Type
fir::factory::Complex::getComplexPartType(mlir::Type complexType) const {
  return mlir::cast<mlir::ComplexType>(complexType).getElementType();
}

mlir::Type fir::factory::Complex::getComplexPartType(mlir::Value cplx) const {
  return getComplexPartType(cplx.getType());
}

mlir::Value fir::factory::Complex::createComplex(mlir::Type cplxTy,
                                                 mlir::Value real,
                                                 mlir::Value imag) {
  mlir::Value und = fir::UndefOp::create(builder, loc, cplxTy);
  return insert<Part::Imag>(insert<Part::Real>(und, real), imag);
}

mlir::Value fir::factory::Complex::createComplex(mlir::Value real,
                                                 mlir::Value imag) {
  assert(real.getType() == imag.getType() && "part types must match");
  mlir::Type cplxTy = mlir::ComplexType::get(real.getType());
  return createComplex(cplxTy, real, imag);
}