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/Common/Fortran.h"
17#include "flang/Frontend/CodeGenOptions.h"
19#include "flang/Lower/AbstractConverter.h"
20#include "flang/Lower/EnvironmentDefault.h"
22#include "flang/Lower/StatementContext.h"
23#include "flang/Optimizer/Builder/FIRBuilder.h"
24#include "flang/Optimizer/Dialect/Support/KindMapping.h"
25#include "mlir/IR/BuiltinOps.h"
26#include "mlir/IR/OwningOpRef.h"
27#include <set>
28
29namespace llvm {
30class TargetMachine;
31} // namespace llvm
32
33namespace Fortran {
34namespace common {
35class IntrinsicTypeDefaultKinds;
36} // namespace common
37namespace evaluate {
38class IntrinsicProcTable;
39class TargetCharacteristics;
40} // namespace evaluate
41namespace parser {
42class AllCookedSources;
43struct Program;
44} // namespace parser
45namespace semantics {
46class SemanticsContext;
47} // namespace semantics
48
49namespace lower {
50
51//===----------------------------------------------------------------------===//
52// Lowering bridge
53//===----------------------------------------------------------------------===//
54
58public:
60 static LoweringBridge
61 create(mlir::MLIRContext &ctx,
64 const Fortran::evaluate::IntrinsicProcTable &intrinsics,
65 const Fortran::evaluate::TargetCharacteristics &targetCharacteristics,
66 const Fortran::parser::AllCookedSources &allCooked,
67 llvm::StringRef triple, fir::KindMapping &kindMap,
68 const Fortran::lower::LoweringOptions &loweringOptions,
69 const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
70 const Fortran::common::LanguageFeatureControl &languageFeatures,
71 const llvm::TargetMachine &targetMachine,
72 const Fortran::frontend::TargetOptions &targetOptions,
73 const Fortran::frontend::CodeGenOptions &codeGenOptions) {
74 return LoweringBridge(ctx, semanticsContext, defaultKinds, intrinsics,
75 targetCharacteristics, allCooked, triple, kindMap,
76 loweringOptions, envDefaults, languageFeatures,
77 targetMachine, targetOptions, codeGenOptions);
78 }
79
80 //===--------------------------------------------------------------------===//
81 // Getters
82 //===--------------------------------------------------------------------===//
83
84 mlir::MLIRContext &getMLIRContext() { return context; }
85
87 mlir::ModuleOp getModule() { return *module; }
88 mlir::ModuleOp getModuleAndRelease() { return module.release(); }
89
90 const Fortran::common::IntrinsicTypeDefaultKinds &getDefaultKinds() const {
91 return defaultKinds;
92 }
93 const Fortran::evaluate::IntrinsicProcTable &getIntrinsicTable() const {
94 return intrinsics;
95 }
97 getTargetCharacteristics() const {
98 return targetCharacteristics;
99 }
100 const Fortran::parser::AllCookedSources *getCookedSource() const {
101 return cooked;
102 }
103
105 const fir::KindMapping &getKindMap() const { return kindMap; }
106
107 const Fortran::lower::LoweringOptions &getLoweringOptions() const {
108 return loweringOptions;
109 }
110
111 const std::vector<Fortran::lower::EnvironmentDefault> &
112 getEnvironmentDefaults() const {
113 return envDefaults;
114 }
115
116 const Fortran::common::LanguageFeatureControl &getLanguageFeatures() const {
117 return languageFeatures;
118 }
119
122
123 Fortran::semantics::SemanticsContext &getSemanticsContext() const {
124 return semanticsContext;
125 }
126
127 Fortran::lower::StatementContext &fctCtx() { return functionContext; }
128
129 Fortran::lower::StatementContext &openAccCtx() { return openAccContext; }
130
131 bool validModule() { return getModule(); }
132
133 //===--------------------------------------------------------------------===//
134 // Perform the creation of an mlir::ModuleOp
135 //===--------------------------------------------------------------------===//
136
139 void parseSourceFile(llvm::SourceMgr &);
140
142 void lower(const Fortran::parser::Program &program,
143 const Fortran::semantics::SemanticsContext &semanticsContext);
144
145private:
146 explicit LoweringBridge(
147 mlir::MLIRContext &ctx,
148 Fortran::semantics::SemanticsContext &semanticsContext,
150 const Fortran::evaluate::IntrinsicProcTable &intrinsics,
151 const Fortran::evaluate::TargetCharacteristics &targetCharacteristics,
152 const Fortran::parser::AllCookedSources &cooked, llvm::StringRef triple,
153 fir::KindMapping &kindMap,
154 const Fortran::lower::LoweringOptions &loweringOptions,
155 const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
156 const Fortran::common::LanguageFeatureControl &languageFeatures,
157 const llvm::TargetMachine &targetMachine,
158 const Fortran::frontend::TargetOptions &targetOptions,
159 const Fortran::frontend::CodeGenOptions &codeGenOptions);
160 LoweringBridge() = delete;
161 LoweringBridge(const LoweringBridge &) = delete;
162
163 Fortran::semantics::SemanticsContext &semanticsContext;
164 Fortran::lower::StatementContext functionContext;
167 const Fortran::evaluate::IntrinsicProcTable &intrinsics;
168 const Fortran::evaluate::TargetCharacteristics &targetCharacteristics;
170 mlir::MLIRContext &context;
171 mlir::OwningOpRef<mlir::ModuleOp> module;
172 fir::KindMapping &kindMap;
173 const Fortran::lower::LoweringOptions &loweringOptions;
174 const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults;
175 const Fortran::common::LanguageFeatureControl &languageFeatures;
176 std::set<std::string> tempNames;
177};
178
179} // namespace lower
180} // namespace Fortran
181
182#endif // FORTRAN_LOWER_BRIDGE_H
Definition: default-kinds.h:26
Definition: Fortran-features.h:84
Definition: common.h:215
Definition: CodeGenOptions.h:49
Options for controlling the target.
Definition: TargetOptions.h:27
Definition: Bridge.h:57
void parseSourceFile(llvm::SourceMgr &)
Definition: Bridge.cpp:6139
mlir::ModuleOp getModule()
Get the ModuleOp. It can never be null, which is asserted in the ctor.
Definition: Bridge.h:87
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:61
const fir::KindMapping & getKindMap() const
Get the kind map.
Definition: Bridge.h:105
Fortran::evaluate::FoldingContext createFoldingContext()
Create a folding context. Careful: this is very expensive.
Definition: Bridge.cpp:6123
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:6128
Definition: LoweringOptions.h:34
Definition: StatementContext.h:46
Definition: provenance.h:281
Definition: semantics.h:67
Definition: KindMapping.h:48
Definition: bit-population-count.h:20