xref: /llvm-project/mlir/include/mlir/Conversion/ComplexToLLVM/ComplexToLLVM.h (revision 206fad0e218e83799e49ca15545d997c6c5e8a03)
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 DialectRegistry;
15 class LLVMTypeConverter;
16 class Pass;
17 class RewritePatternSet;
18 
19 #define GEN_PASS_DECL_CONVERTCOMPLEXTOLLVMPASS
20 #include "mlir/Conversion/Passes.h.inc"
21 
22 class ComplexStructBuilder : public StructBuilder {
23 public:
24   /// Construct a helper for the given complex number value.
25   using StructBuilder::StructBuilder;
26   /// Build IR creating an `undef` value of the complex number type.
27   static ComplexStructBuilder undef(OpBuilder &builder, Location loc,
28                                     Type type);
29 
30   // Build IR extracting the real value from the complex number struct.
31   Value real(OpBuilder &builder, Location loc);
32   // Build IR inserting the real value into the complex number struct.
33   void setReal(OpBuilder &builder, Location loc, Value real);
34 
35   // Build IR extracting the imaginary value from the complex number struct.
36   Value imaginary(OpBuilder &builder, Location loc);
37   // Build IR inserting the imaginary value into the complex number struct.
38   void setImaginary(OpBuilder &builder, Location loc, Value imaginary);
39 };
40 
41 /// Populate the given list with patterns that convert from Complex to LLVM.
42 void populateComplexToLLVMConversionPatterns(const LLVMTypeConverter &converter,
43                                              RewritePatternSet &patterns);
44 
45 void registerConvertComplexToLLVMInterface(DialectRegistry &registry);
46 
47 } // namespace mlir
48 
49 #endif // MLIR_CONVERSION_COMPLEXTOLLVM_COMPLEXTOLLVM_H_
50