Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===-- Lower/Bridge.h -- main interface to lowering ------------*- 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 | #ifndef FORTRAN_LOWER_BRIDGE_H |
14 | #define FORTRAN_LOWER_BRIDGE_H |
15 | |
16 | #include "flang/Common/Fortran.h" |
17 | #include "flang/Lower/AbstractConverter.h" |
18 | #include "flang/Lower/EnvironmentDefault.h" |
19 | #include "flang/Lower/LoweringOptions.h" |
20 | #include "flang/Lower/StatementContext.h" |
21 | #include "flang/Optimizer/Builder/FIRBuilder.h" |
22 | #include "flang/Optimizer/Dialect/Support/KindMapping.h" |
23 | #include "mlir/IR/BuiltinOps.h" |
24 | #include <set> |
25 | |
26 | namespace llvm { |
27 | class TargetMachine; |
28 | } // namespace llvm |
29 | |
30 | namespace Fortran { |
31 | namespace common { |
32 | class IntrinsicTypeDefaultKinds; |
33 | } // namespace common |
34 | namespace evaluate { |
35 | class IntrinsicProcTable; |
36 | class TargetCharacteristics; |
37 | } // namespace evaluate |
38 | namespace parser { |
39 | class AllCookedSources; |
40 | struct Program; |
41 | } // namespace parser |
42 | namespace semantics { |
43 | class SemanticsContext; |
44 | } // namespace semantics |
45 | |
46 | namespace lower { |
47 | |
48 | //===----------------------------------------------------------------------===// |
49 | // Lowering bridge |
50 | //===----------------------------------------------------------------------===// |
51 | |
52 | /// The lowering bridge converts the front-end parse trees and semantics |
53 | /// checking residual to MLIR (FIR dialect) code. |
54 | class LoweringBridge { |
55 | public: |
56 | /// Create a lowering bridge instance. |
57 | static LoweringBridge |
58 | create(mlir::MLIRContext &ctx, |
59 | Fortran::semantics::SemanticsContext &semanticsContext, |
60 | const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds, |
61 | const Fortran::evaluate::IntrinsicProcTable &intrinsics, |
62 | const Fortran::evaluate::TargetCharacteristics &targetCharacteristics, |
63 | const Fortran::parser::AllCookedSources &allCooked, |
64 | llvm::StringRef triple, fir::KindMapping &kindMap, |
65 | const Fortran::lower::LoweringOptions &loweringOptions, |
66 | const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults, |
67 | const Fortran::common::LanguageFeatureControl &languageFeatures, |
68 | const llvm::TargetMachine &targetMachine) { |
69 | return LoweringBridge(ctx, semanticsContext, defaultKinds, intrinsics, |
70 | targetCharacteristics, allCooked, triple, kindMap, |
71 | loweringOptions, envDefaults, languageFeatures, |
72 | targetMachine); |
73 | } |
74 | |
75 | //===--------------------------------------------------------------------===// |
76 | // Getters |
77 | //===--------------------------------------------------------------------===// |
78 | |
79 | mlir::MLIRContext &getMLIRContext() { return context; } |
80 | |
81 | /// Get the ModuleOp. It can never be null, which is asserted in the ctor. |
82 | mlir::ModuleOp &getModule() { return *module.get(); } |
83 | |
84 | const Fortran::common::IntrinsicTypeDefaultKinds &getDefaultKinds() const { |
85 | return defaultKinds; |
86 | } |
87 | const Fortran::evaluate::IntrinsicProcTable &getIntrinsicTable() const { |
88 | return intrinsics; |
89 | } |
90 | const Fortran::evaluate::TargetCharacteristics & |
91 | getTargetCharacteristics() const { |
92 | return targetCharacteristics; |
93 | } |
94 | const Fortran::parser::AllCookedSources *getCookedSource() const { |
95 | return cooked; |
96 | } |
97 | |
98 | /// Get the kind map. |
99 | const fir::KindMapping &getKindMap() const { return kindMap; } |
100 | |
101 | const Fortran::lower::LoweringOptions &getLoweringOptions() const { |
102 | return loweringOptions; |
103 | } |
104 | |
105 | const std::vector<Fortran::lower::EnvironmentDefault> & |
106 | getEnvironmentDefaults() const { |
107 | return envDefaults; |
108 | } |
109 | |
110 | const Fortran::common::LanguageFeatureControl &getLanguageFeatures() const { |
111 | return languageFeatures; |
112 | } |
113 | |
114 | /// Create a folding context. Careful: this is very expensive. |
115 | Fortran::evaluate::FoldingContext createFoldingContext(); |
116 | |
117 | Fortran::semantics::SemanticsContext &getSemanticsContext() const { |
118 | return semanticsContext; |
119 | } |
120 | |
121 | Fortran::lower::StatementContext &fctCtx() { return functionContext; } |
122 | |
123 | Fortran::lower::StatementContext &openAccCtx() { return openAccContext; } |
124 | |
125 | bool validModule() { return getModule(); } |
126 | |
127 | //===--------------------------------------------------------------------===// |
128 | // Perform the creation of an mlir::ModuleOp |
129 | //===--------------------------------------------------------------------===// |
130 | |
131 | /// Read in an MLIR input file rather than lowering Fortran sources. |
132 | /// This is intended to be used for testing. |
133 | void parseSourceFile(llvm::SourceMgr &); |
134 | |
135 | /// Cross the bridge from the Fortran parse-tree, etc. to MLIR dialects |
136 | void lower(const Fortran::parser::Program &program, |
137 | const Fortran::semantics::SemanticsContext &semanticsContext); |
138 | |
139 | private: |
140 | explicit LoweringBridge( |
141 | mlir::MLIRContext &ctx, |
142 | Fortran::semantics::SemanticsContext &semanticsContext, |
143 | const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds, |
144 | const Fortran::evaluate::IntrinsicProcTable &intrinsics, |
145 | const Fortran::evaluate::TargetCharacteristics &targetCharacteristics, |
146 | const Fortran::parser::AllCookedSources &cooked, llvm::StringRef triple, |
147 | fir::KindMapping &kindMap, |
148 | const Fortran::lower::LoweringOptions &loweringOptions, |
149 | const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults, |
150 | const Fortran::common::LanguageFeatureControl &languageFeatures, |
151 | const llvm::TargetMachine &targetMachine); |
152 | LoweringBridge() = delete; |
153 | LoweringBridge(const LoweringBridge &) = delete; |
154 | |
155 | Fortran::semantics::SemanticsContext &semanticsContext; |
156 | Fortran::lower::StatementContext functionContext; |
157 | Fortran::lower::StatementContext openAccContext; |
158 | const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds; |
159 | const Fortran::evaluate::IntrinsicProcTable &intrinsics; |
160 | const Fortran::evaluate::TargetCharacteristics &targetCharacteristics; |
161 | const Fortran::parser::AllCookedSources *cooked; |
162 | mlir::MLIRContext &context; |
163 | std::unique_ptr<mlir::ModuleOp> module; |
164 | fir::KindMapping &kindMap; |
165 | const Fortran::lower::LoweringOptions &loweringOptions; |
166 | const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults; |
167 | const Fortran::common::LanguageFeatureControl &languageFeatures; |
168 | std::set<std::string> tempNames; |
169 | }; |
170 | |
171 | } // namespace lower |
172 | } // namespace Fortran |
173 | |
174 | #endif // FORTRAN_LOWER_BRIDGE_H |
175 |
Warning: This file is not a C or C++ file. It does not have highlighting.