Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions flang/include/flang/Semantics/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class raw_ostream;
}
namespace Fortran::parser {
struct Expr;
struct OpenMPDeclareReductionConstruct;
struct OmpMetadirectiveDirective;
struct OpenMPDeclarativeConstruct;
}

namespace Fortran::semantics {
Expand Down Expand Up @@ -736,9 +735,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &, const GenericDetails &);
class UserReductionDetails {
public:
using TypeVector = std::vector<const DeclTypeSpec *>;
using DeclInfo = std::variant<const parser::OpenMPDeclareReductionConstruct *,
const parser::OmpMetadirectiveDirective *>;
using DeclVector = std::vector<DeclInfo>;
using DeclVector = std::vector<const parser::OpenMPDeclarativeConstruct *>;

UserReductionDetails() = default;

Expand All @@ -756,7 +753,9 @@ class UserReductionDetails {
return false;
}

void AddDecl(const DeclInfo &decl) { declList_.emplace_back(decl); }
void AddDecl(const parser::OpenMPDeclarativeConstruct *decl) {
declList_.emplace_back(decl);
}
const DeclVector &GetDeclList() const { return declList_; }

private:
Expand Down
8 changes: 2 additions & 6 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3082,11 +3082,7 @@ template void Unparse<Expr>(llvm::raw_ostream &, const Expr &,
const common::LangOptions &, Encoding, bool, bool, preStatementType *,
AnalyzedObjectsAsFortran *);

template void Unparse<parser::OpenMPDeclareReductionConstruct>(
llvm::raw_ostream &, const parser::OpenMPDeclareReductionConstruct &,
const common::LangOptions &, Encoding, bool, bool, preStatementType *,
AnalyzedObjectsAsFortran *);
template void Unparse<parser::OmpMetadirectiveDirective>(llvm::raw_ostream &,
const parser::OmpMetadirectiveDirective &, const common::LangOptions &,
template void Unparse<parser::OpenMPDeclarativeConstruct>(llvm::raw_ostream &,
const parser::OpenMPDeclarativeConstruct &, const common::LangOptions &,
Encoding, bool, bool, preStatementType *, AnalyzedObjectsAsFortran *);
} // namespace Fortran::parser
15 changes: 2 additions & 13 deletions flang/lib/Semantics/mod-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,19 +1056,8 @@ void ModFileWriter::PutUserReduction(
// The module content for a OpenMP Declare Reduction is the OpenMP
// declaration. There may be multiple declarations.
// Decls are pointers, so do not use a reference.
for (const auto decl : details.GetDeclList()) {
common::visit( //
common::visitors{//
[&](const parser::OpenMPDeclareReductionConstruct *d) {
Unparse(os, *d, context_.langOptions());
},
[&](const parser::OmpMetadirectiveDirective *m) {
Unparse(os, *m, context_.langOptions());
},
[&](const auto &) {
DIE("Unknown OpenMP DECLARE REDUCTION content");
}},
decl);
for (const auto *decl : details.GetDeclList()) {
Unparse(os, *decl, context_.langOptions());
}
}

Expand Down
20 changes: 9 additions & 11 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,12 +1480,10 @@ class OmpVisitor : public virtual DeclarationVisitor {
static bool NeedsScope(const parser::OmpClause &);

bool Pre(const parser::OmpMetadirectiveDirective &x) { //
metaDirective_ = &x;
++metaLevel_;
return true;
}
void Post(const parser::OmpMetadirectiveDirective &) { //
metaDirective_ = nullptr;
--metaLevel_;
}

Expand Down Expand Up @@ -1583,7 +1581,8 @@ class OmpVisitor : public virtual DeclarationVisitor {
AddOmpSourceRange(x.source);
ProcessReductionSpecifier(
std::get<Indirection<parser::OmpReductionSpecifier>>(x.t).value(),
std::get<std::optional<parser::OmpClauseList>>(x.t), x);
std::get<std::optional<parser::OmpClauseList>>(x.t),
declaratives_.back());
return false;
}
bool Pre(const parser::OmpMapClause &);
Expand Down Expand Up @@ -1684,9 +1683,11 @@ class OmpVisitor : public virtual DeclarationVisitor {
// can implicitly declare variables instead of only using the
// ones already declared in the Fortran sources.
SkipImplicitTyping(true);
declaratives_.push_back(&x);
return true;
}
void Post(const parser::OpenMPDeclarativeConstruct &) {
declaratives_.pop_back();
SkipImplicitTyping(false);
messageHandler().set_currStmtSource(std::nullopt);
}
Expand Down Expand Up @@ -1728,15 +1729,14 @@ class OmpVisitor : public virtual DeclarationVisitor {
private:
void ProcessMapperSpecifier(const parser::OmpMapperSpecifier &spec,
const parser::OmpClauseList &clauses);
template <typename T>
void ProcessReductionSpecifier(const parser::OmpReductionSpecifier &spec,
const std::optional<parser::OmpClauseList> &clauses,
const T &wholeConstruct);
const parser::OpenMPDeclarativeConstruct *wholeConstruct);

void ResolveCriticalName(const parser::OmpArgument &arg);

int metaLevel_{0};
const parser::OmpMetadirectiveDirective *metaDirective_{nullptr};
std::vector<const parser::OpenMPDeclarativeConstruct *> declaratives_;
};

bool OmpVisitor::NeedsScope(const parser::OmpBlockConstruct &x) {
Expand Down Expand Up @@ -1861,11 +1861,10 @@ std::string MangleDefinedOperator(const parser::CharBlock &name) {
return "op" + name.ToString();
}

template <typename T>
void OmpVisitor::ProcessReductionSpecifier(
const parser::OmpReductionSpecifier &spec,
const std::optional<parser::OmpClauseList> &clauses,
const T &wholeOmpConstruct) {
const parser::OpenMPDeclarativeConstruct *construct) {
const parser::Name *name{nullptr};
parser::CharBlock mangledName;
UserReductionDetails reductionDetailsTemp;
Expand Down Expand Up @@ -1952,7 +1951,7 @@ void OmpVisitor::ProcessReductionSpecifier(
PopScope();
}

reductionDetails->AddDecl(&wholeOmpConstruct);
reductionDetails->AddDecl(construct);

if (!symbol) {
symbol = &MakeSymbol(mangledName, Attrs{}, std::move(*reductionDetails));
Expand Down Expand Up @@ -2017,8 +2016,7 @@ bool OmpVisitor::Pre(const parser::OmpDirectiveSpecification &x) {
if (maybeArgs && maybeClauses) {
const parser::OmpArgument &first{maybeArgs->v.front()};
if (auto *spec{std::get_if<parser::OmpReductionSpecifier>(&first.u)}) {
CHECK(metaDirective_);
ProcessReductionSpecifier(*spec, maybeClauses, *metaDirective_);
ProcessReductionSpecifier(*spec, maybeClauses, declaratives_.back());
}
}
break;
Expand Down