Skip to content
Closed
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
2 changes: 0 additions & 2 deletions flang/include/flang/Parser/openmp-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ MAKE_CONSTR_ID(OmpErrorDirective, D::OMPD_error);
MAKE_CONSTR_ID(OmpMetadirectiveDirective, D::OMPD_metadirective);
MAKE_CONSTR_ID(OpenMPDeclarativeAllocate, D::OMPD_allocate);
MAKE_CONSTR_ID(OpenMPDeclarativeAssumes, D::OMPD_assumes);
MAKE_CONSTR_ID(OpenMPDeclareMapperConstruct, D::OMPD_declare_mapper);
MAKE_CONSTR_ID(OpenMPDeclareReductionConstruct, D::OMPD_declare_reduction);
MAKE_CONSTR_ID(OpenMPDeclareSimdConstruct, D::OMPD_declare_simd);
MAKE_CONSTR_ID(OpenMPDeclareTargetConstruct, D::OMPD_declare_target);
Expand Down Expand Up @@ -105,7 +104,6 @@ struct DirectiveNameScope {
std::is_same_v<T, OmpMetadirectiveDirective> ||
std::is_same_v<T, OpenMPDeclarativeAllocate> ||
std::is_same_v<T, OpenMPDeclarativeAssumes> ||
std::is_same_v<T, OpenMPDeclareMapperConstruct> ||
std::is_same_v<T, OpenMPDeclareReductionConstruct> ||
std::is_same_v<T, OpenMPDeclareSimdConstruct> ||
std::is_same_v<T, OpenMPDeclareTargetConstruct> ||
Expand Down
10 changes: 4 additions & 6 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4951,20 +4951,18 @@ struct OpenMPDeclareTargetConstruct {
// OMP v5.2: 5.8.8
// declare-mapper -> DECLARE MAPPER ([mapper-name :] type :: var) map-clauses
struct OpenMPDeclareMapperConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPDeclareMapperConstruct);
WRAPPER_CLASS_BOILERPLATE(
OpenMPDeclareMapperConstruct, OmpDirectiveSpecification);
CharBlock source;
std::tuple<Verbatim, OmpMapperSpecifier, OmpClauseList> t;
};

// ref: 5.2: Section 5.5.11 139-141
// 2.16 declare-reduction -> DECLARE REDUCTION (reduction-identifier : type-list
// : combiner) [initializer-clause]
struct OpenMPDeclareReductionConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPDeclareReductionConstruct);
WRAPPER_CLASS_BOILERPLATE(
OpenMPDeclareReductionConstruct, OmpDirectiveSpecification);
CharBlock source;
std::tuple<Verbatim, common::Indirection<OmpReductionSpecifier>,
std::optional<OmpClauseList>>
t;
};

// 2.8.2 declare-simd -> DECLARE SIMD [(proc-name)] [declare-simd-clause[ [,]
Expand Down
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
26 changes: 13 additions & 13 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3441,18 +3441,20 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
TODO(converter.getCurrentLocation(), "OpenMPDeclareSimdConstruct");
}

static void
genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
const parser::OpenMPDeclareMapperConstruct &declareMapperConstruct) {
mlir::Location loc = converter.genLocation(declareMapperConstruct.source);
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPDeclareMapperConstruct &construct) {
mlir::Location loc = converter.genLocation(construct.source);
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
const parser::OmpArgumentList &args = construct.v.Arguments();
assert(args.v.size() == 1 && "Expecting single argument");
lower::StatementContext stmtCtx;
const auto &spec =
std::get<parser::OmpMapperSpecifier>(declareMapperConstruct.t);
const auto &mapperName{std::get<std::string>(spec.t)};
const auto &varType{std::get<parser::TypeSpec>(spec.t)};
const auto &varName{std::get<parser::Name>(spec.t)};
const auto *spec = std::get_if<parser::OmpMapperSpecifier>(&args.v.front().u);
assert(spec && "Expecting mapper specifier");
const auto &mapperName{std::get<std::string>(spec->t)};
const auto &varType{std::get<parser::TypeSpec>(spec->t)};
const auto &varName{std::get<parser::Name>(spec->t)};
assert(varType.declTypeSpec->category() ==
semantics::DeclTypeSpec::Category::TypeDerived &&
"Expected derived type");
Expand All @@ -3476,9 +3478,7 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,

// Populate the declareMapper region with the map information.
mlir::omp::DeclareMapperInfoOperands clauseOps;
const auto *clauseList{
parser::Unwrap<parser::OmpClauseList>(declareMapperConstruct.t)};
List<Clause> clauses = makeClauses(*clauseList, semaCtx);
List<Clause> clauses = makeClauses(construct.v.Clauses(), semaCtx);
ClauseProcessor cp(converter, semaCtx, clauses);
cp.processMap(loc, stmtCtx, clauseOps);
mlir::omp::DeclareMapperInfoOp::create(firOpBuilder, loc, clauseOps.mapVars);
Expand Down
11 changes: 6 additions & 5 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1708,9 +1708,9 @@ TYPE_PARSER(sourced(construct<OmpDeclareVariantDirective>(

// 2.16 Declare Reduction Construct
TYPE_PARSER(sourced(construct<OpenMPDeclareReductionConstruct>(
verbatim("DECLARE REDUCTION"_tok) || verbatim("DECLARE_REDUCTION"_tok),
"(" >> indirect(Parser<OmpReductionSpecifier>{}) / ")",
maybe(Parser<OmpClauseList>{}))))
predicated(Parser<OmpDirectiveName>{},
IsDirective(llvm::omp::Directive::OMPD_declare_reduction)) >=
Parser<OmpDirectiveSpecification>{})))

// declare-target with list
TYPE_PARSER(sourced(construct<OmpDeclareTargetWithList>(
Expand Down Expand Up @@ -1756,8 +1756,9 @@ TYPE_PARSER(applyFunction<OmpMapperSpecifier>(ConstructOmpMapperSpecifier,

// OpenMP 5.2: 5.8.8 Declare Mapper Construct
TYPE_PARSER(sourced(construct<OpenMPDeclareMapperConstruct>(
verbatim("DECLARE MAPPER"_tok) || verbatim("DECLARE_MAPPER"_tok),
parenthesized(Parser<OmpMapperSpecifier>{}), Parser<OmpClauseList>{})))
predicated(Parser<OmpDirectiveName>{},
IsDirective(llvm::omp::Directive::OMPD_declare_mapper)) >=
Parser<OmpDirectiveSpecification>{})))

TYPE_PARSER(construct<OmpReductionCombiner>(Parser<AssignmentStmt>{}) ||
construct<OmpReductionCombiner>(Parser<FunctionReference>{}))
Expand Down
32 changes: 7 additions & 25 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2495,11 +2495,8 @@ class UnparseVisitor {
}
void Unparse(const OpenMPDeclareReductionConstruct &x) {
BeginOpenMP();
Word("!$OMP DECLARE REDUCTION ");
Put("(");
Walk(std::get<common::Indirection<OmpReductionSpecifier>>(x.t));
Put(")");
Walk(std::get<std::optional<OmpClauseList>>(x.t));
Word("!$OMP ");
Walk(x.v);
Put("\n");
EndOpenMP();
}
Expand Down Expand Up @@ -2547,21 +2544,10 @@ class UnparseVisitor {
Put("\n");
EndOpenMP();
}
void Unparse(const OpenMPDeclareMapperConstruct &z) {
void Unparse(const OpenMPDeclareMapperConstruct &x) {
BeginOpenMP();
Word("!$OMP DECLARE MAPPER (");
const auto &spec{std::get<OmpMapperSpecifier>(z.t)};
const auto &mapperName{std::get<std::string>(spec.t)};
if (mapperName.find(llvm::omp::OmpDefaultMapperName) == std::string::npos) {
Walk(mapperName);
Put(":");
}
Walk(std::get<TypeSpec>(spec.t));
Put("::");
Walk(std::get<Name>(spec.t));
Put(")");

Walk(std::get<OmpClauseList>(z.t));
Word("!$OMP ");
Walk(x.v);
Put("\n");
EndOpenMP();
}
Expand Down Expand Up @@ -3082,11 +3068,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
54 changes: 34 additions & 20 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,16 +629,6 @@ template <typename Checker> struct DirectiveSpellingVisitor {
checker_(std::get<parser::Verbatim>(x.t).source, Directive::OMPD_assumes);
return false;
}
bool Pre(const parser::OpenMPDeclareMapperConstruct &x) {
checker_(
std::get<parser::Verbatim>(x.t).source, Directive::OMPD_declare_mapper);
return false;
}
bool Pre(const parser::OpenMPDeclareReductionConstruct &x) {
checker_(std::get<parser::Verbatim>(x.t).source,
Directive::OMPD_declare_reduction);
return false;
}
bool Pre(const parser::OpenMPDeclareSimdConstruct &x) {
checker_(
std::get<parser::Verbatim>(x.t).source, Directive::OMPD_declare_simd);
Expand Down Expand Up @@ -1595,13 +1585,25 @@ void OmpStructureChecker::Leave(const parser::OmpDeclareTargetWithClause &x) {
}

void OmpStructureChecker::Enter(const parser::OpenMPDeclareMapperConstruct &x) {
const auto &dir{std::get<parser::Verbatim>(x.t)};
PushContextAndClauseSets(
dir.source, llvm::omp::Directive::OMPD_declare_mapper);
const auto &spec{std::get<parser::OmpMapperSpecifier>(x.t)};
const auto &type = std::get<parser::TypeSpec>(spec.t);
if (!std::get_if<parser::DerivedTypeSpec>(&type.u)) {
context_.Say(dir.source, "Type is not a derived type"_err_en_US);
const parser::OmpDirectiveName &dirName{x.v.DirName()};
PushContextAndClauseSets(dirName.source, dirName.v);

const parser::OmpArgumentList &args{x.v.Arguments()};
if (args.v.size() != 1) {
context_.Say(args.source,
"DECLARE_MAPPER directive should have a single argument"_err_en_US);
return;
}

const parser::OmpArgument &arg{args.v.front()};
if (auto *spec{std::get_if<parser::OmpMapperSpecifier>(&arg.u)}) {
const auto &type = std::get<parser::TypeSpec>(spec->t);
if (!std::get_if<parser::DerivedTypeSpec>(&type.u)) {
context_.Say(arg.source, "Type is not a derived type"_err_en_US);
}
} else {
context_.Say(arg.source,
"The argument to the DECLARE_MAPPER directive should be a mapper-specifier"_err_en_US);
}
}

Expand All @@ -1611,9 +1613,21 @@ void OmpStructureChecker::Leave(const parser::OpenMPDeclareMapperConstruct &) {

void OmpStructureChecker::Enter(
const parser::OpenMPDeclareReductionConstruct &x) {
const auto &dir{std::get<parser::Verbatim>(x.t)};
PushContextAndClauseSets(
dir.source, llvm::omp::Directive::OMPD_declare_reduction);
const parser::OmpDirectiveName &dirName{x.v.DirName()};
PushContextAndClauseSets(dirName.source, dirName.v);

const parser::OmpArgumentList &args{x.v.Arguments()};
if (args.v.size() != 1) {
context_.Say(args.source,
"DECLARE_REDUCTION directive should have a single argument"_err_en_US);
return;
}

const parser::OmpArgument &arg{args.v.front()};
if (!std::holds_alternative<parser::OmpReductionSpecifier>(arg.u)) {
context_.Say(arg.source,
"The argument to the DECLARE_REDUCTION directive should be a reduction-specifier"_err_en_US);
}
}

void OmpStructureChecker::Leave(
Expand Down
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
3 changes: 2 additions & 1 deletion flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,8 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPDeclareTargetConstruct &x) {
}

bool OmpAttributeVisitor::Pre(const parser::OpenMPDeclareMapperConstruct &x) {
PushContext(x.source, llvm::omp::Directive::OMPD_declare_mapper);
const parser::OmpDirectiveName &dirName{x.v.DirName()};
PushContext(dirName.source, dirName.v);
return true;
}

Expand Down
Loading