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 llvm {
31class TargetMachine;
32} // namespace llvm
33
34namespace Fortran {
35namespace common {
37} // namespace common
38namespace evaluate {
39class IntrinsicProcTable;
41} // namespace evaluate
42namespace parser {
44struct Program;
45} // namespace parser
46namespace semantics {
48} // namespace semantics
49
50namespace lower {
51
52//===----------------------------------------------------------------------===//
53// Lowering bridge
54//===----------------------------------------------------------------------===//
55
58class LoweringBridge {
59public:
61 static LoweringBridge
62 create(mlir::MLIRContext &ctx,
65 const Fortran::evaluate::IntrinsicProcTable &intrinsics,
66 const Fortran::evaluate::TargetCharacteristics &targetCharacteristics,
67 const Fortran::parser::AllCookedSources &allCooked,
68 llvm::StringRef triple, fir::KindMapping &kindMap,
69 const Fortran::lower::LoweringOptions &loweringOptions,
70 const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
71 const Fortran::common::LanguageFeatureControl &languageFeatures,
72 const llvm::TargetMachine &targetMachine,
73 const Fortran::frontend::TargetOptions &targetOptions,
74 const Fortran::frontend::CodeGenOptions &codeGenOptions) {
75 return LoweringBridge(ctx, semanticsContext, defaultKinds, intrinsics,
76 targetCharacteristics, allCooked, triple, kindMap,
77 loweringOptions, envDefaults, languageFeatures,
78 targetMachine, targetOptions, codeGenOptions);
79 }
81
82 //===--------------------------------------------------------------------===//
83 // Getters
84 //===--------------------------------------------------------------------===//
85
86 mlir::MLIRContext &getMLIRContext() { return context; }
87
89 mlir::ModuleOp getModule() { return *module; }
90 mlir::ModuleOp getModuleAndRelease() { return module.release(); }
91
92 const Fortran::common::IntrinsicTypeDefaultKinds &getDefaultKinds() const {
93 return defaultKinds;
94 }
95 const Fortran::evaluate::IntrinsicProcTable &getIntrinsicTable() const {
96 return intrinsics;
97 }
98 const Fortran::evaluate::TargetCharacteristics &
99 getTargetCharacteristics() const {
100 return targetCharacteristics;
101 }
102 const Fortran::parser::AllCookedSources *getCookedSource() const {
103 return cooked;
104 }
105
107 const fir::KindMapping &getKindMap() const { return kindMap; }
108
109 const Fortran::lower::LoweringOptions &getLoweringOptions() const {
110 return loweringOptions;
111 }
112
113 const std::vector<Fortran::lower::EnvironmentDefault> &
114 getEnvironmentDefaults() const {
115 return envDefaults;
116 }
117
118 const Fortran::common::LanguageFeatureControl &getLanguageFeatures() const {
119 return languageFeatures;
120 }
121
122 const std::string &getModuleNameHash() const { return moduleNameHash; }
123
125 Fortran::evaluate::FoldingContext createFoldingContext();
126
127 Fortran::semantics::SemanticsContext &getSemanticsContext() const {
128 return semanticsContext;
129 }
130
131 Fortran::lower::StatementContext &fctCtx() { return functionContext; }
132
133 Fortran::lower::StatementContext &cudaCleanupCtx() {
134 return cudaCleanupContext;
135 }
136
137 Fortran::lower::StatementContext &openAccCtx() { return openAccContext; }
138
139 bool validModule() { return getModule(); }
140
141 //===--------------------------------------------------------------------===//
142 // Perform the creation of an mlir::ModuleOp
143 //===--------------------------------------------------------------------===//
144
147 void parseSourceFile(llvm::SourceMgr &);
148
150 void lower(const Fortran::parser::Program &program,
151 const Fortran::semantics::SemanticsContext &semanticsContext);
152
153private:
154 explicit LoweringBridge(
155 mlir::MLIRContext &ctx,
156 Fortran::semantics::SemanticsContext &semanticsContext,
157 const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds,
158 const Fortran::evaluate::IntrinsicProcTable &intrinsics,
159 const Fortran::evaluate::TargetCharacteristics &targetCharacteristics,
160 const Fortran::parser::AllCookedSources &cooked, llvm::StringRef triple,
161 fir::KindMapping &kindMap,
162 const Fortran::lower::LoweringOptions &loweringOptions,
163 const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
164 const Fortran::common::LanguageFeatureControl &languageFeatures,
165 const llvm::TargetMachine &targetMachine,
166 const Fortran::frontend::TargetOptions &targetOptions,
167 const Fortran::frontend::CodeGenOptions &codeGenOptions);
168 LoweringBridge() = delete;
169 LoweringBridge(const LoweringBridge &) = delete;
170
171 Fortran::semantics::SemanticsContext &semanticsContext;
172 Fortran::lower::StatementContext functionContext;
173 Fortran::lower::StatementContext cudaCleanupContext;
174 Fortran::lower::StatementContext openAccContext;
175 const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds;
176 const Fortran::evaluate::IntrinsicProcTable &intrinsics;
177 const Fortran::evaluate::TargetCharacteristics &targetCharacteristics;
178 const Fortran::parser::AllCookedSources *cooked;
179 mlir::MLIRContext &context;
180 mlir::OwningOpRef<mlir::ModuleOp> module;
181 fir::KindMapping &kindMap;
182 const Fortran::lower::LoweringOptions &loweringOptions;
183 const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults;
184 const Fortran::common::LanguageFeatureControl &languageFeatures;
185 std::set<std::string> tempNames;
186 std::string moduleNameHash;
187 std::optional<mlir::DiagnosticEngine::HandlerID> diagHandlerID;
188};
189
190} // namespace lower
191} // namespace Fortran
192
193#endif // FORTRAN_LOWER_BRIDGE_H
Definition default-kinds.h:26
Definition Fortran-features.h:101
Definition CodeGenOptions.h:50
Options for controlling the target.
Definition TargetOptions.h:27
Definition Bridge.h:58
void parseSourceFile(llvm::SourceMgr &)
Definition Bridge.cpp:7042
mlir::ModuleOp getModule()
Get the ModuleOp. It can never be null, which is asserted in the ctor.
Definition Bridge.h:89
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, const llvm::TargetMachine &targetMachine, const Fortran::frontend::TargetOptions &targetOptions, const Fortran::frontend::CodeGenOptions &codeGenOptions)
Create a lowering bridge instance.
Definition Bridge.h:62
const fir::KindMapping & getKindMap() const
Get the kind map.
Definition Bridge.h:107
Fortran::evaluate::FoldingContext createFoldingContext()
Create a folding context. Careful: this is very expensive.
Definition Bridge.cpp:7028
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:7033
Definition LoweringOptions.h:48
Definition provenance.h:286
Definition semantics.h:67
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