FLANG
Bridge.h
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/Frontend/CodeGenOptions.h"
18#include "flang/Lower/AbstractConverter.h"
19#include "flang/Lower/EnvironmentDefault.h"
21#include "flang/Lower/StatementContext.h"
22#include "flang/Optimizer/Builder/FIRBuilder.h"
23#include "flang/Optimizer/Dialect/Support/KindMapping.h"
24#include "flang/Support/Fortran.h"
25#include "mlir/IR/BuiltinOps.h"
26#include "mlir/IR/OwningOpRef.h"
27#include "llvm/ProfileData/SampleProf.h"
28#include <set>
29
30namespace Fortran {
31namespace common {
33} // namespace common
34namespace evaluate {
35class IntrinsicProcTable;
37} // namespace evaluate
38namespace parser {
40struct Program;
41} // namespace parser
42namespace semantics {
44} // namespace semantics
45
46namespace lower {
47
48//===----------------------------------------------------------------------===//
49// Lowering bridge
50//===----------------------------------------------------------------------===//
51
54class LoweringBridge {
55public:
57 static LoweringBridge
58 create(mlir::MLIRContext &ctx,
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 llvm::StringRef targetFeatures,
69 const Fortran::frontend::TargetOptions &targetOptions,
70 const Fortran::frontend::CodeGenOptions &codeGenOptions) {
71 return LoweringBridge(ctx, semanticsContext, defaultKinds, intrinsics,
72 targetCharacteristics, allCooked, triple, kindMap,
73 loweringOptions, envDefaults, languageFeatures,
74 targetFeatures, targetOptions, codeGenOptions);
75 }
77
78 //===--------------------------------------------------------------------===//
79 // Getters
80 //===--------------------------------------------------------------------===//
81
82 mlir::MLIRContext &getMLIRContext() { return context; }
83
85 mlir::ModuleOp getModule() { return *module; }
86 mlir::ModuleOp getModuleAndRelease() { return module.release(); }
87
88 const Fortran::common::IntrinsicTypeDefaultKinds &getDefaultKinds() const {
89 return defaultKinds;
90 }
91 const Fortran::evaluate::IntrinsicProcTable &getIntrinsicTable() const {
92 return intrinsics;
93 }
94 const Fortran::evaluate::TargetCharacteristics &
95 getTargetCharacteristics() const {
96 return targetCharacteristics;
97 }
98 const Fortran::parser::AllCookedSources *getCookedSource() const {
99 return cooked;
100 }
101
103 const fir::KindMapping &getKindMap() const { return kindMap; }
104
105 const Fortran::lower::LoweringOptions &getLoweringOptions() const {
106 return loweringOptions;
107 }
108
109 const std::vector<Fortran::lower::EnvironmentDefault> &
110 getEnvironmentDefaults() const {
111 return envDefaults;
112 }
113
114 const Fortran::common::LanguageFeatureControl &getLanguageFeatures() const {
115 return languageFeatures;
116 }
117
118 const std::string &getModuleNameHash() const { return moduleNameHash; }
119
121 Fortran::evaluate::FoldingContext createFoldingContext();
122
123 Fortran::semantics::SemanticsContext &getSemanticsContext() const {
124 return semanticsContext;
125 }
126
127 Fortran::lower::StatementContext &fctCtx() { return functionContext; }
128
129 Fortran::lower::StatementContext &cudaCleanupCtx() {
130 return cudaCleanupContext;
131 }
132
133 Fortran::lower::StatementContext &openAccCtx() { return openAccContext; }
134
135 bool validModule() { return getModule(); }
136
137 //===--------------------------------------------------------------------===//
138 // Perform the creation of an mlir::ModuleOp
139 //===--------------------------------------------------------------------===//
140
143 void parseSourceFile(llvm::SourceMgr &);
144
146 void lower(const Fortran::parser::Program &program,
147 const Fortran::semantics::SemanticsContext &semanticsContext);
148
149private:
150 explicit LoweringBridge(
151 mlir::MLIRContext &ctx,
152 Fortran::semantics::SemanticsContext &semanticsContext,
153 const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds,
154 const Fortran::evaluate::IntrinsicProcTable &intrinsics,
155 const Fortran::evaluate::TargetCharacteristics &targetCharacteristics,
156 const Fortran::parser::AllCookedSources &cooked, llvm::StringRef triple,
157 fir::KindMapping &kindMap,
158 const Fortran::lower::LoweringOptions &loweringOptions,
159 const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
160 const Fortran::common::LanguageFeatureControl &languageFeatures,
161 llvm::StringRef targetFeatures,
162 const Fortran::frontend::TargetOptions &targetOptions,
163 const Fortran::frontend::CodeGenOptions &codeGenOptions);
164 LoweringBridge() = delete;
165 LoweringBridge(const LoweringBridge &) = delete;
166
167 Fortran::semantics::SemanticsContext &semanticsContext;
168 Fortran::lower::StatementContext functionContext;
169 Fortran::lower::StatementContext cudaCleanupContext;
170 Fortran::lower::StatementContext openAccContext;
171 const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds;
172 const Fortran::evaluate::IntrinsicProcTable &intrinsics;
173 const Fortran::evaluate::TargetCharacteristics &targetCharacteristics;
174 const Fortran::parser::AllCookedSources *cooked;
175 mlir::MLIRContext &context;
176 mlir::OwningOpRef<mlir::ModuleOp> module;
177 fir::KindMapping &kindMap;
178 const Fortran::lower::LoweringOptions &loweringOptions;
179 const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults;
180 const Fortran::common::LanguageFeatureControl &languageFeatures;
181 std::set<std::string> tempNames;
182 std::string moduleNameHash;
183 std::optional<mlir::DiagnosticEngine::HandlerID> diagHandlerID;
184};
185
186} // namespace lower
187} // namespace Fortran
188
189#endif // FORTRAN_LOWER_BRIDGE_H
Definition default-kinds.h:26
Definition Fortran-features.h:103
Definition CodeGenOptions.h:50
Options for controlling the target.
Definition TargetOptions.h:27
Definition Bridge.h:54
static LoweringBridge create(mlir::MLIRContext &ctx, Fortran::semantics::SemanticsContext &semanticsContext, const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds, const Fortran::evaluate::IntrinsicProcTable &intrinsics, const Fortran::evaluate::TargetCharacteristics &targetCharacteristics, const Fortran::parser::AllCookedSources &allCooked, llvm::StringRef triple, fir::KindMapping &kindMap, const Fortran::lower::LoweringOptions &loweringOptions, const std::vector< Fortran::lower::EnvironmentDefault > &envDefaults, const Fortran::common::LanguageFeatureControl &languageFeatures, llvm::StringRef targetFeatures, const Fortran::frontend::TargetOptions &targetOptions, const Fortran::frontend::CodeGenOptions &codeGenOptions)
Create a lowering bridge instance.
Definition Bridge.h:58
void parseSourceFile(llvm::SourceMgr &)
Definition Bridge.cpp:7641
mlir::ModuleOp getModule()
Get the ModuleOp. It can never be null, which is asserted in the ctor.
Definition Bridge.h:85
const fir::KindMapping & getKindMap() const
Get the kind map.
Definition Bridge.h:103
Fortran::evaluate::FoldingContext createFoldingContext()
Create a folding context. Careful: this is very expensive.
Definition Bridge.cpp:7627
void lower(const Fortran::parser::Program &program, const Fortran::semantics::SemanticsContext &semanticsContext)
Cross the bridge from the Fortran parse-tree, etc. to MLIR dialects.
Definition Bridge.cpp:7632
Definition LoweringOptions.h:48
Definition provenance.h:286
Definition semantics.h:71
Definition KindMapping.h:48
Definition bit-population-count.h:20
Definition call.h:34
Definition ParserActions.h:24
Definition check-expression.h:19
Definition bit-population-count.h:20