Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===-- ConvertConstant.h -- lowering of constants --------------*- C++ -*-===// |
---|---|
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 | // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | /// |
13 | /// Implements the conversion from evaluate::Constant to FIR. |
14 | /// |
15 | //===----------------------------------------------------------------------===// |
16 | |
17 | #ifndef FORTRAN_LOWER_CONVERTCONSTANT_H |
18 | #define FORTRAN_LOWER_CONVERTCONSTANT_H |
19 | |
20 | #include "flang/Evaluate/constant.h" |
21 | #include "flang/Lower/Support/Utils.h" |
22 | #include "flang/Optimizer/Builder/BoxValue.h" |
23 | #include "flang/Optimizer/Builder/FIRBuilder.h" |
24 | |
25 | namespace Fortran::lower { |
26 | class AbstractConverter; |
27 | |
28 | /// Class to lower evaluate::Constant to fir::ExtendedValue. |
29 | template <typename T> |
30 | class ConstantBuilder { |
31 | public: |
32 | /// Lower \p constant into a fir::ExtendedValue. |
33 | /// If \p outlineBigConstantsInReadOnlyMemory is set, character, derived |
34 | /// type, and array constants will be lowered into read only memory |
35 | /// fir.global, and the resulting fir::ExtendedValue will contain the address |
36 | /// of the fir.global. This option should not be set if the constant is being |
37 | /// lowered while the builder is already in a fir.global body because |
38 | /// fir.global initialization body cannot contain code manipulating memory |
39 | /// (e.g. fir.load/fir.store...). |
40 | static fir::ExtendedValue gen(Fortran::lower::AbstractConverter &converter, |
41 | mlir::Location loc, |
42 | const evaluate::Constant<T> &constant, |
43 | bool outlineBigConstantsInReadOnlyMemory); |
44 | }; |
45 | using namespace evaluate; |
46 | FOR_EACH_SPECIFIC_TYPE(extern template class ConstantBuilder, ) |
47 | |
48 | template <typename T> |
49 | fir::ExtendedValue convertConstant(Fortran::lower::AbstractConverter &converter, |
50 | mlir::Location loc, |
51 | const evaluate::Constant<T> &constant, |
52 | bool outlineBigConstantsInReadOnlyMemory) { |
53 | return ConstantBuilder<T>::gen(converter, loc, constant, |
54 | outlineBigConstantsInReadOnlyMemory); |
55 | } |
56 | |
57 | /// Create a fir.global array with a dense attribute containing the value of |
58 | /// \p initExpr. |
59 | /// Using a dense attribute allows faster MLIR compilation times compared to |
60 | /// creating an initialization body for the initial value. However, a dense |
61 | /// attribute can only be created if initExpr is a non-empty rank 1 numerical or |
62 | /// logical Constant<T>. Otherwise, the value returned will be null. |
63 | fir::GlobalOp tryCreatingDenseGlobal(fir::FirOpBuilder &builder, |
64 | mlir::Location loc, mlir::Type symTy, |
65 | llvm::StringRef globalName, |
66 | mlir::StringAttr linkage, bool isConst, |
67 | const Fortran::lower::SomeExpr &initExpr); |
68 | |
69 | /// Lower a StructureConstructor that must be lowered in read only data although |
70 | /// it may not be wrapped into a Constant<T> (this may be the case for derived |
71 | /// type descriptor compiler generated data that is not fully compliant with |
72 | /// Fortran constant expression but can and must still be lowered into read only |
73 | /// memory). |
74 | fir::ExtendedValue |
75 | genInlinedStructureCtorLit(Fortran::lower::AbstractConverter &converter, |
76 | mlir::Location loc, |
77 | const Fortran::evaluate::StructureConstructor &ctor); |
78 | |
79 | } // namespace Fortran::lower |
80 | |
81 | #endif // FORTRAN_LOWER_CONVERTCONSTANT_H |
82 |
Warning: This file is not a C or C++ file. It does not have highlighting.