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 if (auto createOp = dyn_cast_or_null<CreateOp>(getOperand().getDefiningOp())) 28 return createOp.getOperand(0); 29 return {}; 30 } 31 32 OpFoldResult ImOp::fold(ArrayRef<Attribute> operands) { 33 assert(operands.size() == 1 && "unary op takes 1 operand"); 34 ArrayAttr arrayAttr = operands[0].dyn_cast_or_null<ArrayAttr>(); 35 if (arrayAttr && arrayAttr.size() == 2) 36 return arrayAttr[1]; 37 if (auto createOp = dyn_cast_or_null<CreateOp>(getOperand().getDefiningOp())) 38 return createOp.getOperand(1); 39 return {}; 40 } 41