FLANG

Bridge.h
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
16
17 #ifndef FORTRAN_LOWER_BRIDGE_H
18 #define FORTRAN_LOWER_BRIDGE_H
19
20 #include "flang/Common/Fortran.h"
21 #include "flang/Lower/AbstractConverter.h"
22 #include "flang/Optimizer/Support/KindMapping.h"
23 #include "mlir/IR/Module.h"
24
25 namespace fir {
26 struct NameUniquer;
27 }
28
29 namespace Fortran {
30 namespace common {
31 class IntrinsicTypeDefaultKinds;
32 } // namespace common
33 namespace evaluate {
34 class IntrinsicProcTable;
35 } // namespace evaluate
36 namespace parser {
37 class CookedSource;
38 struct Program;
39 } // namespace parser
40 namespace semantics {
41 class SemanticsContext;
42 } // namespace semantics
43
44 namespace lower {
45
46 //===----------------------------------------------------------------------===//
47 // Lowering bridge
48 //===----------------------------------------------------------------------===//
49
52 class LoweringBridge {
53 public:
55 static LoweringBridge
56 create(const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds,
57 const Fortran::evaluate::IntrinsicProcTable &intrinsics,
58 const Fortran::parser::CookedSource &cooked) {
59 return LoweringBridge{defaultKinds, intrinsics, cooked};
60 }
61
62 //===--------------------------------------------------------------------===//
63 // Getters
64 //===--------------------------------------------------------------------===//
65
66 mlir::MLIRContext &getMLIRContext() { return *context.get(); }
67 mlir::ModuleOp &getModule() { return *module.get(); }
68 const Fortran::common::IntrinsicTypeDefaultKinds &getDefaultKinds() const {
69 return defaultKinds;
70 }
71 const Fortran::evaluate::IntrinsicProcTable &getIntrinsicTable() const {
72 return intrinsics;
73 }
74 const Fortran::parser::CookedSource *getCookedSource() const {
75 return cooked;
76 }
77
79 const fir::KindMapping &getKindMap() const { return kindMap; }
80
82 Fortran::evaluate::FoldingContext createFoldingContext() const;
83
84 bool validModule() { return getModule(); }
85
86 //===--------------------------------------------------------------------===//
87 // Perform the creation of an mlir::ModuleOp
88 //===--------------------------------------------------------------------===//
89
92 void parseSourceFile(llvm::SourceMgr &);
93
95 void lower(const Fortran::parser::Program &program, fir::NameUniquer &uniquer,
96 const Fortran::semantics::SemanticsContext &semanticsContext);
97
98 private:
99 explicit LoweringBridge(
100 const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds,
101 const Fortran::evaluate::IntrinsicProcTable &intrinsics,
102 const Fortran::parser::CookedSource &cooked);
103 LoweringBridge() = delete;
104 LoweringBridge(const LoweringBridge &) = delete;
105
106 const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds;
107 const Fortran::evaluate::IntrinsicProcTable &intrinsics;
108 const Fortran::parser::CookedSource *cooked;
109 std::unique_ptr<mlir::MLIRContext> context;
110 std::unique_ptr<mlir::ModuleOp> module;
111 fir::KindMapping kindMap;
112 };
113
114 } // namespace lower
115 } // namespace Fortran
116
117 #endif // FORTRAN_LOWER_BRIDGE_H
Fortran::semantics::SemanticsContext
Definition: semantics.h:60
Fortran::parser::CookedSource
Definition: provenance.h:216
Fortran::lower::LoweringBridge::lower
void lower(const Fortran::parser::Program &program, fir::NameUniquer &uniquer, const Fortran::semantics::SemanticsContext &semanticsContext)
Cross the bridge from the Fortran parse-tree, etc. to MLIR dialects.
Fortran::lower::LoweringBridge
Definition: Bridge.h:52
Fortran::common::IntrinsicTypeDefaultKinds
Definition: default-kinds.h:26
Fortran::evaluate::FoldingContext
Definition: common.h:209
Fortran::lower::LoweringBridge::create
static LoweringBridge create(const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds, const Fortran::evaluate::IntrinsicProcTable &intrinsics, const Fortran::parser::CookedSource &cooked)
Create a lowering bridge instance.
Definition: Bridge.h:56
Fortran::lower::LoweringBridge::parseSourceFile
void parseSourceFile(llvm::SourceMgr &)
fir::KindMapping
Definition: KindMapping.h:43
Fortran::lower::LoweringBridge::createFoldingContext
Fortran::evaluate::FoldingContext createFoldingContext() const
Create a folding context. Careful: this is very expensive.
Fortran::lower::LoweringBridge::getKindMap
const fir::KindMapping & getKindMap() const
Get the kind map.
Definition: Bridge.h:79
fir::NameUniquer
Definition: InternalNames.h:29