-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
Bridge.h
118 lines (98 loc) · 4.12 KB
/
Bridge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//===-- Lower/Bridge.h -- main interface to lowering ------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
//
//===----------------------------------------------------------------------===//
#ifndef FORTRAN_LOWER_BRIDGE_H
#define FORTRAN_LOWER_BRIDGE_H
#include "flang/Common/Fortran.h"
#include "flang/Lower/AbstractConverter.h"
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Support/KindMapping.h"
#include "mlir/IR/BuiltinOps.h"
namespace Fortran {
namespace common {
class IntrinsicTypeDefaultKinds;
} // namespace common
namespace evaluate {
class IntrinsicProcTable;
} // namespace evaluate
namespace parser {
class AllCookedSources;
struct Program;
} // namespace parser
namespace semantics {
class SemanticsContext;
} // namespace semantics
namespace lower {
//===----------------------------------------------------------------------===//
// Lowering bridge
//===----------------------------------------------------------------------===//
/// The lowering bridge converts the front-end parse trees and semantics
/// checking residual to MLIR (FIR dialect) code.
class LoweringBridge {
public:
/// Create a lowering bridge instance.
static LoweringBridge
create(mlir::MLIRContext &ctx,
const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds,
const Fortran::evaluate::IntrinsicProcTable &intrinsics,
const Fortran::parser::AllCookedSources &allCooked,
llvm::StringRef triple, fir::KindMapping &kindMap) {
return LoweringBridge(ctx, defaultKinds, intrinsics, allCooked, triple,
kindMap);
}
//===--------------------------------------------------------------------===//
// Getters
//===--------------------------------------------------------------------===//
mlir::MLIRContext &getMLIRContext() { return context; }
/// Get the ModuleOp. It can never be null, which is asserted in the ctor.
mlir::ModuleOp &getModule() { return *module.get(); }
const Fortran::common::IntrinsicTypeDefaultKinds &getDefaultKinds() const {
return defaultKinds;
}
const Fortran::evaluate::IntrinsicProcTable &getIntrinsicTable() const {
return intrinsics;
}
const Fortran::parser::AllCookedSources *getCookedSource() const {
return cooked;
}
/// Get the kind map.
const fir::KindMapping &getKindMap() const { return kindMap; }
/// Create a folding context. Careful: this is very expensive.
Fortran::evaluate::FoldingContext createFoldingContext() const;
bool validModule() { return getModule(); }
//===--------------------------------------------------------------------===//
// Perform the creation of an mlir::ModuleOp
//===--------------------------------------------------------------------===//
/// Read in an MLIR input file rather than lowering Fortran sources.
/// This is intended to be used for testing.
void parseSourceFile(llvm::SourceMgr &);
/// Cross the bridge from the Fortran parse-tree, etc. to MLIR dialects
void lower(const Fortran::parser::Program &program,
const Fortran::semantics::SemanticsContext &semanticsContext);
private:
explicit LoweringBridge(
mlir::MLIRContext &ctx,
const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds,
const Fortran::evaluate::IntrinsicProcTable &intrinsics,
const Fortran::parser::AllCookedSources &cooked, llvm::StringRef triple,
fir::KindMapping &kindMap);
LoweringBridge() = delete;
LoweringBridge(const LoweringBridge &) = delete;
const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds;
const Fortran::evaluate::IntrinsicProcTable &intrinsics;
const Fortran::parser::AllCookedSources *cooked;
mlir::MLIRContext &context;
std::unique_ptr<mlir::ModuleOp> module;
fir::KindMapping &kindMap;
};
} // namespace lower
} // namespace Fortran
#endif // FORTRAN_LOWER_BRIDGE_H