1 //===- ComplexToLLVM.h - Utils to convert from the complex dialect --------===// 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 #ifndef MLIR_CONVERSION_COMPLEXTOLLVM_COMPLEXTOLLVM_H_ 9 #define MLIR_CONVERSION_COMPLEXTOLLVM_COMPLEXTOLLVM_H_ 10 11 #include "mlir/Conversion/LLVMCommon/StructBuilder.h" 12 13 namespace mlir { 14 class LLVMTypeConverter; 15 class Pass; 16 class RewritePatternSet; 17 18 class ComplexStructBuilder : public StructBuilder { 19 public: 20 /// Construct a helper for the given complex number value. 21 using StructBuilder::StructBuilder; 22 /// Build IR creating an `undef` value of the complex number type. 23 static ComplexStructBuilder undef(OpBuilder &builder, Location loc, 24 Type type); 25 26 // Build IR extracting the real value from the complex number struct. 27 Value real(OpBuilder &builder, Location loc); 28 // Build IR inserting the real value into the complex number struct. 29 void setReal(OpBuilder &builder, Location loc, Value real); 30 31 // Build IR extracting the imaginary value from the complex number struct. 32 Value imaginary(OpBuilder &builder, Location loc); 33 // Build IR inserting the imaginary value into the complex number struct. 34 void setImaginary(OpBuilder &builder, Location loc, Value imaginary); 35 }; 36 37 /// Populate the given list with patterns that convert from Complex to LLVM. 38 void populateComplexToLLVMConversionPatterns(LLVMTypeConverter &converter, 39 RewritePatternSet &patterns); 40 41 /// Create a pass to convert Complex operations to the LLVMIR dialect. 42 std::unique_ptr<Pass> createConvertComplexToLLVMPass(); 43 44 } // namespace mlir 45 46 #endif // MLIR_CONVERSION_COMPLEXTOLLVM_COMPLEXTOLLVM_H_ 47