Skip to content

Commit 4d9479f

Browse files
authored
[flang][openacc] Allow open acc routines from other modules. (#136012)
OpenACC routines annotations in separate compilation units currently get ignored, which leads to errors in compilation. There are two reason for currently ignoring open acc routine information and this PR is addressing both. - The module file reader doesn't read back in openacc directives from module files. - Simple fix in `flang/lib/Semantics/mod-file.cpp` - The lowering to HLFIR doesn't generate routine directives for symbols imported from other modules that are openacc routines. - This is the majority of this diff, and is address by the changes that start in `flang/lib/Lower/CallInterface.cpp`.
1 parent b3a6d43 commit 4d9479f

File tree

12 files changed

+454
-362
lines changed

12 files changed

+454
-362
lines changed

flang/include/flang/Lower/OpenACC.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class StringRef;
2222
} // namespace llvm
2323

2424
namespace mlir {
25+
namespace func {
26+
class FuncOp;
27+
} // namespace func
2528
class Location;
2629
class Type;
2730
class ModuleOp;
@@ -31,9 +34,13 @@ class Value;
3134

3235
namespace fir {
3336
class FirOpBuilder;
34-
}
37+
} // namespace fir
3538

3639
namespace Fortran {
40+
namespace evaluate {
41+
struct ProcedureDesignator;
42+
} // namespace evaluate
43+
3744
namespace parser {
3845
struct AccClauseList;
3946
struct OpenACCConstruct;
@@ -42,6 +49,7 @@ struct OpenACCRoutineConstruct;
4249
} // namespace parser
4350

4451
namespace semantics {
52+
class OpenACCRoutineInfo;
4553
class SemanticsContext;
4654
class Symbol;
4755
} // namespace semantics
@@ -55,9 +63,6 @@ namespace pft {
5563
struct Evaluation;
5664
} // namespace pft
5765

58-
using AccRoutineInfoMappingList =
59-
llvm::SmallVector<std::pair<std::string, mlir::SymbolRefAttr>>;
60-
6166
static constexpr llvm::StringRef declarePostAllocSuffix =
6267
"_acc_declare_update_desc_post_alloc";
6368
static constexpr llvm::StringRef declarePreDeallocSuffix =
@@ -71,19 +76,12 @@ mlir::Value genOpenACCConstruct(AbstractConverter &,
7176
Fortran::semantics::SemanticsContext &,
7277
pft::Evaluation &,
7378
const parser::OpenACCConstruct &);
74-
void genOpenACCDeclarativeConstruct(AbstractConverter &,
75-
Fortran::semantics::SemanticsContext &,
76-
StatementContext &,
77-
const parser::OpenACCDeclarativeConstruct &,
78-
AccRoutineInfoMappingList &);
79-
void genOpenACCRoutineConstruct(AbstractConverter &,
80-
Fortran::semantics::SemanticsContext &,
81-
mlir::ModuleOp,
82-
const parser::OpenACCRoutineConstruct &,
83-
AccRoutineInfoMappingList &);
84-
85-
void finalizeOpenACCRoutineAttachment(mlir::ModuleOp,
86-
AccRoutineInfoMappingList &);
79+
void genOpenACCDeclarativeConstruct(
80+
AbstractConverter &, Fortran::semantics::SemanticsContext &,
81+
StatementContext &, const parser::OpenACCDeclarativeConstruct &);
82+
void genOpenACCRoutineConstruct(
83+
AbstractConverter &, mlir::ModuleOp, mlir::func::FuncOp,
84+
const std::vector<Fortran::semantics::OpenACCRoutineInfo> &);
8785

8886
/// Get a acc.private.recipe op for the given type or create it if it does not
8987
/// exist yet.

flang/include/flang/Semantics/symbol.h

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <list>
2323
#include <optional>
2424
#include <set>
25+
#include <variant>
2526
#include <vector>
2627

2728
namespace llvm {
@@ -127,6 +128,9 @@ class WithBindName {
127128
// Device type specific OpenACC routine information
128129
class OpenACCRoutineDeviceTypeInfo {
129130
public:
131+
explicit OpenACCRoutineDeviceTypeInfo(
132+
Fortran::common::OpenACCDeviceType dType)
133+
: deviceType_{dType} {}
130134
bool isSeq() const { return isSeq_; }
131135
void set_isSeq(bool value = true) { isSeq_ = value; }
132136
bool isVector() const { return isVector_; }
@@ -137,22 +141,30 @@ class OpenACCRoutineDeviceTypeInfo {
137141
void set_isGang(bool value = true) { isGang_ = value; }
138142
unsigned gangDim() const { return gangDim_; }
139143
void set_gangDim(unsigned value) { gangDim_ = value; }
140-
const std::string *bindName() const {
141-
return bindName_ ? &*bindName_ : nullptr;
144+
const std::variant<std::string, SymbolRef> *bindName() const {
145+
return bindName_.has_value() ? &*bindName_ : nullptr;
142146
}
143-
void set_bindName(std::string &&name) { bindName_ = std::move(name); }
144-
void set_dType(Fortran::common::OpenACCDeviceType dType) {
145-
deviceType_ = dType;
147+
const std::optional<std::variant<std::string, SymbolRef>> &
148+
bindNameOpt() const {
149+
return bindName_;
146150
}
151+
void set_bindName(std::string &&name) { bindName_.emplace(std::move(name)); }
152+
void set_bindName(SymbolRef symbol) { bindName_.emplace(symbol); }
153+
147154
Fortran::common::OpenACCDeviceType dType() const { return deviceType_; }
148155

156+
friend llvm::raw_ostream &operator<<(
157+
llvm::raw_ostream &, const OpenACCRoutineDeviceTypeInfo &);
158+
149159
private:
150160
bool isSeq_{false};
151161
bool isVector_{false};
152162
bool isWorker_{false};
153163
bool isGang_{false};
154164
unsigned gangDim_{0};
155-
std::optional<std::string> bindName_;
165+
// bind("name") -> std::string
166+
// bind(sym) -> SymbolRef (requires namemangling in lowering)
167+
std::optional<std::variant<std::string, SymbolRef>> bindName_;
156168
Fortran::common::OpenACCDeviceType deviceType_{
157169
Fortran::common::OpenACCDeviceType::None};
158170
};
@@ -162,15 +174,29 @@ class OpenACCRoutineDeviceTypeInfo {
162174
// in as objects in the OpenACCRoutineDeviceTypeInfo list.
163175
class OpenACCRoutineInfo : public OpenACCRoutineDeviceTypeInfo {
164176
public:
177+
OpenACCRoutineInfo()
178+
: OpenACCRoutineDeviceTypeInfo(Fortran::common::OpenACCDeviceType::None) {
179+
}
165180
bool isNohost() const { return isNohost_; }
166181
void set_isNohost(bool value = true) { isNohost_ = value; }
167-
std::list<OpenACCRoutineDeviceTypeInfo> &deviceTypeInfos() {
182+
const std::list<OpenACCRoutineDeviceTypeInfo> &deviceTypeInfos() const {
168183
return deviceTypeInfos_;
169184
}
170-
void add_deviceTypeInfo(OpenACCRoutineDeviceTypeInfo &info) {
171-
deviceTypeInfos_.push_back(info);
185+
186+
OpenACCRoutineDeviceTypeInfo &add_deviceTypeInfo(
187+
Fortran::common::OpenACCDeviceType type) {
188+
return add_deviceTypeInfo(OpenACCRoutineDeviceTypeInfo(type));
189+
}
190+
191+
OpenACCRoutineDeviceTypeInfo &add_deviceTypeInfo(
192+
OpenACCRoutineDeviceTypeInfo &&info) {
193+
deviceTypeInfos_.push_back(std::move(info));
194+
return deviceTypeInfos_.back();
172195
}
173196

197+
friend llvm::raw_ostream &operator<<(
198+
llvm::raw_ostream &, const OpenACCRoutineInfo &);
199+
174200
private:
175201
std::list<OpenACCRoutineDeviceTypeInfo> deviceTypeInfos_;
176202
bool isNohost_{false};

0 commit comments

Comments
 (0)