13#ifndef FORTRAN_OPTIMIZER_BUILDER_COMPLEX_H
14#define FORTRAN_OPTIMIZER_BUILDER_COMPLEX_H
16#include "flang/Optimizer/Builder/FIRBuilder.h"
18namespace fir::factory {
24 : builder(builder), loc(loc) {}
29 enum class Part { Real = 0, Imag = 1 };
36 mlir::Value
createComplex(mlir::Type complexType, mlir::Value real,
40 mlir::Value
createComplex(mlir::Value real, mlir::Value imag);
44 return isImagPart ? extract<Part::Imag>(cplx) : extract<Part::Real>(cplx);
48 std::pair<mlir::Value, mlir::Value>
extractParts(mlir::Value cplx) {
49 return {extract<Part::Real>(cplx), extract<Part::Imag>(cplx)};
52 mlir::Value insertComplexPart(mlir::Value cplx, mlir::Value part,
54 return isImagPart ? insert<Part::Imag>(cplx, part)
55 : insert<Part::Real>(cplx, part);
59 template <Part partId>
60 mlir::Value extract(mlir::Value cplx) {
61 return builder.create<fir::ExtractValueOp>(
63 builder.getArrayAttr({builder.getIntegerAttr(
64 builder.getIndexType(),
static_cast<int>(partId))}));
67 template <Part partId>
68 mlir::Value insert(mlir::Value cplx, mlir::Value part) {
69 return builder.create<fir::InsertValueOp>(
70 loc, cplx.getType(), cplx, part,
71 builder.getArrayAttr({builder.getIntegerAttr(
72 builder.getIndexType(),
static_cast<int>(partId))}));
75 template <Part partId>
76 mlir::Value createPartId() {
78 static_cast<int>(partId));
82 FirOpBuilder &builder;
Definition: FIRBuilder.h:55
mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType, std::int64_t i)
Definition: FIRBuilder.cpp:131
Helper to facilitate lowering of COMPLEX manipulations in FIR.
Definition: Complex.h:21
std::pair< mlir::Value, mlir::Value > extractParts(mlir::Value cplx)
Returns (Real, Imag) pair of cplx.
Definition: Complex.h:48
mlir::Value createComplex(mlir::Type complexType, mlir::Value real, mlir::Value imag)
Create a complex value.
Definition: Complex.cpp:24
mlir::Value extractComplexPart(mlir::Value cplx, bool isImagPart)
Returns the Real/Imag part of cplx.
Definition: Complex.h:43
mlir::Type getComplexPartType(mlir::Value cplx) const
Get the Complex Type. Determine the type. Do not create MLIR operations.
Definition: Complex.cpp:20