1 //===- ComplexOps.cpp - MLIR Complex Operations ---------------------------===// 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/Complex/IR/Complex.h" 10 #include "mlir/IR/Builders.h" 11 12 using namespace mlir; 13 using namespace mlir::complex; 14 15 //===----------------------------------------------------------------------===// 16 // TableGen'd op method definitions 17 //===----------------------------------------------------------------------===// 18 19 #define GET_OP_CLASSES 20 #include "mlir/Dialect/Complex/IR/ComplexOps.cpp.inc" 21 22 OpFoldResult ReOp::fold(ArrayRef<Attribute> operands) { 23 assert(operands.size() == 1 && "unary op takes 1 operand"); 24 ArrayAttr arrayAttr = operands[0].dyn_cast_or_null<ArrayAttr>(); 25 if (arrayAttr && arrayAttr.size() == 2) 26 return arrayAttr[0]; 27 return {}; 28 } 29 30 OpFoldResult ImOp::fold(ArrayRef<Attribute> operands) { 31 assert(operands.size() == 1 && "unary op takes 1 operand"); 32 ArrayAttr arrayAttr = operands[0].dyn_cast_or_null<ArrayAttr>(); 33 if (arrayAttr && arrayAttr.size() == 2) 34 return arrayAttr[1]; 35 return {}; 36 } 37