[flang] Update unparse.cc and move declarative directives for now.

Original-commit: flang-compiler/f18@d79503f98f
Reviewed-on: https://github.com/flang-compiler/f18/pull/96
Tree-same-pre-rewrite: false
This commit is contained in:
Hongyon Suauthai
2018-06-01 10:40:13 -07:00
parent db9bfab89d
commit 1bfb843a29
4 changed files with 354 additions and 44 deletions

View File

@@ -81,8 +81,10 @@ TYPE_PARSER(construct<OmpScheduleModifierType>(
"NONMONOTONIC" >> pure(OmpScheduleModifierType::ModType::Nonmonotonic) ||
"SIMD" >> pure(OmpScheduleModifierType::ModType::Simd)))
TYPE_PARSER(construct<OmpScheduleModifier>(Parser<OmpScheduleModifierType>{}, maybe(","_ch >> Parser<OmpScheduleModifierType>{})))
TYPE_PARSER(construct<OmpScheduleClause>(
optionalList(Parser<OmpScheduleModifierType>{}),
maybe(Parser<OmpScheduleModifier>{}),
"STATIC" >> pure(OmpScheduleClause::ScheduleType::Static) ||
"DYNAMIC" >> pure(OmpScheduleClause::ScheduleType::Dynamic) ||
"GUIDED" >> pure(OmpScheduleClause::ScheduleType::Guided) ||
@@ -128,11 +130,11 @@ TYPE_PARSER(construct<OmpReductionOperator>(reductionBinaryOperator) ||
construct<OmpReductionOperator>(reductionProcedureOperator))
TYPE_PARSER(construct<OmpReductionClause>(
Parser<OmpReductionOperator>{}, nonemptyList(designator)))
Parser<OmpReductionOperator>{} / ":"_ch, nonemptyList(designator)))
// DEPEND(SOURCE | SINK : vec | (IN | OUT | INOUT) : list
TYPE_PARSER(construct<OmpDependSinkVecLength>(
Parser<DefinedOperator>{}, scalarIntConstantExpr))
indirect(Parser<DefinedOperator>{}), scalarIntConstantExpr))
TYPE_PARSER(
construct<OmpDependSinkVec>(name, maybe(Parser<OmpDependSinkVecLength>{})))
@@ -172,7 +174,7 @@ TYPE_PARSER(construct<OmpAlignedClause>(
TYPE_PARSER(construct<OmpNameList>(pure(OmpNameList::Kind::Object), name) ||
construct<OmpNameList>("/" >> pure(OmpNameList::Kind::Common), name / "/"))
TYPE_CONTEXT_PARSER("Omp Clause"_en_US,
TYPE_PARSER(
construct<OmpClause>(construct<OmpClause::Defaultmap>("DEFAULTMAP"_tok >> parenthesized("TOFROM"_tok >> ":"_ch >> "SCALAR"_tok))) ||
construct<OmpClause>(construct<OmpClause::Inbranch>("INBRANCH"_tok)) ||
construct<OmpClause>(construct<OmpClause::Mergeable>("MERGEABLE"_tok)) ||
@@ -278,15 +280,6 @@ TYPE_PARSER(
construct<OmpLoopDirective>(construct<OmpLoopDirective::TeamsDistribute>(
"TEAMS DISTRIBUTE"_tok >> many(Parser<OmpClause>{}))))
TYPE_PARSER(construct<OmpDeclDirective>(construct<OmpDeclDirective::DeclareReduction>(
"DECLARE REDUCTION"_tok >> many(Parser<OmpClause>{}))) ||
construct<OmpDeclDirective>(construct<OmpDeclDirective::DeclareSimd>(
"DECLARE SIMD"_tok >> many(Parser<OmpClause>{}))) ||
construct<OmpDeclDirective>(construct<OmpDeclDirective::DeclareTarget>(
"DECLARE TARGET"_tok >> many(Parser<OmpClause>{}))) ||
construct<OmpDeclDirective>(construct<OmpDeclDirective::Threadprivate>(
"THREADPRIVATE"_tok >> many(Parser<OmpClause>{}))))
TYPE_PARSER(construct<OmpStandaloneDirective>(
construct<OmpStandaloneDirective::Barrier>(
"BARRIER"_tok >> many(Parser<OmpClause>{}))) ||
@@ -320,17 +313,12 @@ TYPE_PARSER(
TYPE_PARSER(construct<OpenMPStandaloneConstruct>(
statement(Parser<OmpStandaloneDirective>{})))
TYPE_PARSER(
construct<OpenMPDeclConstruct>(statement(Parser<OmpDeclDirective>{})))
TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
beginOmpDirective >>
(construct<OpenMPConstruct>(
indirect(Parser<OpenMPStandaloneConstruct>{})) ||
construct<OpenMPConstruct>(
indirect(Parser<OpenMPLoopConstruct>{})) ||
construct<OpenMPConstruct>(
indirect(Parser<OpenMPDeclConstruct>{}))))
indirect(Parser<OpenMPLoopConstruct>{}))))
} // namespace Fortran::parser
#endif // OPENMP_PARSER_GRAMMAR_H_

View File

@@ -250,7 +250,6 @@ struct AssignedGotoStmt;
struct PauseStmt;
struct OpenMPConstruct;
struct OmpClause;
struct OmpDeclDirective;
struct OmpStandaloneDirective;
struct OmpLoopDirective;
struct OmpEndDirective;
@@ -3221,20 +3220,24 @@ struct OmpMapClause {
std::tuple<std::optional<Type>, std::list<Name>> t;
};
// schedule-modifier -> MONOTONIC | NONMONOTONIC | SIMD
// schedule-modifier-type -> MONOTONIC | NONMONOTONIC | SIMD
struct OmpScheduleModifierType {
ENUM_CLASS(ModType, Monotonic, Nonmonotonic, Simd)
WRAPPER_CLASS_BOILERPLATE(OmpScheduleModifierType, ModType);
};
// SCHEDULE([schedule-modifier [,schedule-modifier]] kind [, Chunksize])
struct OmpScheduleModifier {
TUPLE_CLASS_BOILERPLATE(OmpScheduleModifier);
WRAPPER_CLASS(Modifier1, OmpScheduleModifierType);
WRAPPER_CLASS(Modifier2, OmpScheduleModifierType);
std::tuple<Modifier1, std::optional<Modifier2>> t;
};
// SCHEDULE([schedule-modifier [,schedule-modifier]] schedule-type [, chunksize])
struct OmpScheduleClause {
TUPLE_CLASS_BOILERPLATE(OmpScheduleClause);
ENUM_CLASS(ScheduleType, Static, Dynamic, Guided, Auto, Runtime)
WRAPPER_CLASS(Chunksize, ScalarIntExpr);
std::tuple<std::list<OmpScheduleModifierType>, std::optional<ScheduleType>,
Chunksize>
t;
std::tuple<std::optional<OmpScheduleModifier>, ScheduleType, std::optional<ScalarIntExpr>> t;
};
// IF(DirectiveNameModifier: scalar-logical-expr)
@@ -3369,15 +3372,6 @@ struct OmpClause {
OmpScheduleClause> u;
};
struct OmpDeclDirective {
UNION_CLASS_BOILERPLATE(OmpDeclDirective);
WRAPPER_CLASS(DeclareReduction, std::list<OmpClause>);
WRAPPER_CLASS(DeclareSimd, std::list<OmpClause>);
WRAPPER_CLASS(DeclareTarget, std::list<OmpClause>);
WRAPPER_CLASS(Threadprivate, std::list<OmpClause>);
std::variant<DeclareReduction, DeclareSimd, DeclareTarget, Threadprivate> u;
};
struct OmpLoopDirective {
UNION_CLASS_BOILERPLATE(OmpLoopDirective);
WRAPPER_CLASS(DistributeParallelDoSimd, std::list<OmpClause>);
@@ -3440,13 +3434,12 @@ struct OpenMPLoopConstruct {
t;
};
WRAPPER_CLASS(OpenMPDeclConstruct, Statement<OmpDeclDirective>);
WRAPPER_CLASS(OpenMPStandaloneConstruct, Statement<OmpStandaloneDirective>);
struct OpenMPConstruct {
UNION_CLASS_BOILERPLATE(OpenMPConstruct);
std::variant<Indirection<OpenMPStandaloneConstruct>,
Indirection<OpenMPDeclConstruct>, Indirection<OpenMPLoopConstruct>> u;
Indirection<OpenMPLoopConstruct>> u;
};
} // namespace parser

View File

@@ -1648,6 +1648,329 @@ public:
}
Walk(std::get<Name>(x.t));
}
// OpenMP Clauses & Directives
void Unparse(const OmpNameList &x) {
bool isCommon{std::get<OmpNameList::Kind>(x.t) == OmpNameList::Kind::Common};
const char *slash{isCommon ? "/" : ""};
Put(slash), Walk(std::get<Name>(x.t)), Put(slash);
}
void Unparse(const OmpMapClause &x) {
Word(" MAP("), Walk(std::get<std::optional<OmpMapClause::Type>>(x.t), ":");
Walk(std::get<std::list<Name>>(x.t), ", ");
Put(") ");
}
void Unparse(const OmpScheduleModifier &x) {
Walk(std::get<OmpScheduleModifier::Modifier1>(x.t));
Walk(",", std::get<std::optional<OmpScheduleModifier::Modifier2>>(x.t));
}
void Unparse(const OmpScheduleClause &x) {
Word(" SCHEDULE(");
Walk(std::get<std::optional<OmpScheduleModifier>>(x.t));
Walk(std::get<OmpScheduleClause::ScheduleType>(x.t));
Walk(std::get<std::optional<ScalarIntExpr>>(x.t));
Put(")");
}
void Unparse(const OmpAlignedClause &x) {
Word(" ALIGNED("), Walk(std::get<std::list<Name>>(x.t), ",");
Walk(std::get<std::optional<ScalarIntConstantExpr>>(x.t));
Put(") ");
}
void Unparse(const OmpIfClause &x) {
Word(" IF("), Walk(std::get<std::optional<OmpIfClause::DirectiveNameModifier>>(x.t), ":");
Walk(std::get<ScalarLogicalExpr>(x.t));
Put(") ");
}
void Unparse(const OmpLinearClause::WithoutModifier &x) {
Word(" LINEAR("), Walk(x.names, ", ");
Walk(":", x.step);
Put(")");
}
void Unparse(const OmpLinearClause::WithModifier &x) {
Word(" LINEAR("), Walk(x.modifier), Put("("), Walk(x.names, ","), Put(")");
Walk(":", x.step);
Put(")");
}
void Unparse(const OmpReductionClause &x) {
Word(" REDUCTION(");
Walk(std::get<OmpReductionOperator>(x.t));
Put(":");
Walk(std::get<std::list<Designator>>(x.t), ",");
Put(")");
}
void Unparse(const OmpDependSinkVecLength &x) {
Walk(std::get<Indirection<DefinedOperator>>(x.t));
Walk(std::get<ScalarIntConstantExpr>(x.t));
}
void Unparse(const OmpDependSinkVec &x) {
Walk(std::get<Name>(x.t));
Walk(std::get<std::optional<OmpDependSinkVecLength>>(x.t));
}
void Unparse(const OmpDependClause::InOut &x) {
Walk(std::get<OmpDependenceType>(x.t));
Put(":");
Walk(std::get<std::list<Designator>>(x.t), ",");
}
void Unparse(const OmpDependClause &x) {
std::visit(
visitors{[&](const OmpDependClause::Source &y) {
Word(" DEPEND(SOURCE)");
},
[&](const OmpDependClause::Sink &y) {
Word(" DEPEND(SINK:");
Walk(y.v);
Put(")");
},
[&](const OmpDependClause::InOut &y) {
Word(" DEPEND("); Walk(y.t); Put(")");
}},
x.u);
}
void Before(const OmpClause::Defaultmap &x) {
Word(" DEFAULTMAP(TOFROM:SCALAR)");
}
void Before(const OmpClause::Inbranch &x) {
Word(" INBRANCH");
}
void Before(const OmpClause::Mergeable &x) {
Word(" MERGEABLE");
}
void Before(const OmpClause::Nogroup &x) {
Word(" NOGROUP");
}
void Before(const OmpClause::Notinbranch &x) {
Word(" NOTINBRANCH");
}
void Before(const OmpClause::Nowait &x) {
Word(" NOWAIT");
}
void Before(const OmpClause::Untied &x) {
Word(" UNTIED");
}
void Unparse(const OmpClause::Collapse &x) {
Word(" COLLAPSE("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::Copyin &x) {
Word(" COPYIN("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::Copyprivate &x) {
Word(" COPYPRIVATE("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::Device &x) {
Word(" DEVICE("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::DistSchedule &x) {
Word(" DIST_SCHEDULE(STATIC,"); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::Final &x) {
Word(" FINAL("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::Firstprivate &x) {
Word(" FIRSTPRIVATE("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::From &x) {
Word(" FROM("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::Grainsize &x) {
Word(" GRAINSIZE("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::Lastprivate &x) {
Word(" LASTPRIVATE("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::Link &x) {
Word(" LINK("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::NumTasks &x) {
Word(" NUM_TASKS("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::NumTeams &x) {
Word(" NUM_TEAMS("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::NumThreads &x) {
Word(" NUM_THREADS("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::Ordered &x) {
Word(" ORDERED"); Walk("(", x.v, ")");
}
void Unparse(const OmpClause::Priority &x) {
Word(" PRIORITY("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::Private &x) {
Word(" PRIVATE("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::Safelen &x) {
Word(" SAFELEN("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::ThreadLimit &x) {
Word(" THREADLIMIT("); Walk(x.v); Put(")");
}
void Unparse(const OmpClause::Shared &x) {
Word(" SHARED("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::To &x) {
Word(" TO("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::Uniform &x) {
Word(" UNIFORM("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpClause::UseDevicePtr &x) {
Word(" USE_DEVICE_PTR("); Walk(x.v, ","); Put(")");
}
void Unparse(const OmpLoopDirective &x) {
std::visit(
visitors{[&](const OmpLoopDirective::DistributeParallelDoSimd &y) {
Word("DISTRIBUTE PARALLEL DO SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::DistributeParallelDo &y) {
Word("DISTRIBUTE PARALLEL DO");
Walk(y.v);
},
[&](const OmpLoopDirective::DistributeSimd &y) {
Word("DISTRIBUTE SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::Distribute &y) {
Word("DISTRIBUTE");
Walk(y.v);
},
[&](const OmpLoopDirective::DoSimd &y) {
Word("DO SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::Do &y) {
Word("DO");
Walk(y.v);
},
[&](const OmpLoopDirective::ParallelDoSimd &y) {
Word("PARALLEL DO SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::ParallelDo &y) {
Word("PARALLEL DO");
Walk(y.v);
},
[&](const OmpLoopDirective::Simd &y) {
Word("SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::TargetParallelDoSimd &y) {
Word("TARGET PARALLEL DO SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::TargetParallelDo &y) {
Word("TARGET PARALLEL DO");
Walk(y.v);
},
[&](const OmpLoopDirective::TargetTeamsDistributeParallelDoSimd &y) {
Word("TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::TargetTeamsDistributeParallelDo &y) {
Word("TARGET TEAMS DISTRIBUTE PARALLEL DO");
Walk(y.v);
},
[&](const OmpLoopDirective::TargetTeamsDistributeSimd &y) {
Word("TARGET TEAMS DISTRIBUTE SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::TargetTeamsDistribute &y) {
Word("TARGET TEAMS DISTRIBUTE");
Walk(y.v);
},
[&](const OmpLoopDirective::TargetSimd &y) {
Word("TARGET SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::TaskloopSimd &y) {
Word("TASKLOOP SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::Taskloop &y) {
Word("TASKLOOP");
Walk(y.v);
},
[&](const OmpLoopDirective::TeamsDistributeParallelDoSimd &y) {
Word("TEAMS DISTRIBUTE PARALLEL DO SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::TeamsDistributeParallelDo &y) {
Word("TEAMS DISTRIBUTE PARALLEL DO");
Walk(y.v);
},
[&](const OmpLoopDirective::TeamsDistributeSimd &y) {
Word("TEAMS DISTRIBUTE SIMD");
Walk(y.v);
},
[&](const OmpLoopDirective::TeamsDistribute &y) {
Word("TEAMS DISTRIBUTE");
Walk(y.v);
}},
x.u);
Put("\n");
Indent();
}
void Unparse(const OmpStandaloneDirective &x) {
std::visit(
visitors{[&](const OmpStandaloneDirective::Barrier &y) {
Word("BARRIER");
Walk(y.v);
},
[&](const OmpStandaloneDirective::CancellationPoint &y) {
Word("CANCELLATION POINT");
Walk(y.v);
},
[&](const OmpStandaloneDirective::Cancel &y) {
Word("CANCEL");
Walk(y.v);
},
[&](const OmpStandaloneDirective::Flush &y) {
Word("FLUSH");
Walk(y.v);
},
[&](const OmpStandaloneDirective::TargetEnterData &y) {
Word("TARGET ENTER DATA");
Walk(y.v);
},
[&](const OmpStandaloneDirective::TargetExitData &y) {
Word("TARGET EXIT DATA");
Walk(y.v);
},
[&](const OmpStandaloneDirective::TargetUpdate &y) {
Word("TARGET UPDATE");
Walk(y.v);
},
[&](const OmpStandaloneDirective::Taskwait &y) {
Word("TASKWAIT");
Walk(y.v);
},
[&](const OmpStandaloneDirective::Taskyield &y) {
Word("TASKYIELD");
Walk(y.v);
}},
x.u);
Put("\n");
Indent();
}
void Unparse(const OmpEndDirective &x) {
Outdent();
std::visit(
visitors{[&](const OmpLoopDirective &y) {
Word("!$OMP END ");
Walk(y);
}},
x.u);
}
void Unparse(const OpenMPStandaloneConstruct &x) {
Outdent();
Word("!$OMP ");
Walk(x.v);
}
bool Pre(const OpenMPLoopConstruct &x) {
Outdent();
Word("!$OMP ");
return true;
}
void Unparse(const BasedPointerStmt &x) {
Word("POINTER ("), Walk(std::get<0>(x.t)), Put(", ");
Walk(std::get<1>(x.t));
@@ -1711,6 +2034,16 @@ public:
WALK_NESTED_ENUM(InquireSpec::LogVar, Kind)
WALK_NESTED_ENUM(ProcedureStmt, Kind) // R1506
WALK_NESTED_ENUM(UseStmt, ModuleNature) // R1410
WALK_NESTED_ENUM(OmpProcBindClause, Type) // OMP PROC_BIND
WALK_NESTED_ENUM(OmpDefaultClause, Type) // OMP DEFAULT
WALK_NESTED_ENUM(OmpScheduleModifierType, ModType) // OMP schedule-modifier
WALK_NESTED_ENUM(OmpLinearModifier, Type) // OMP linear-modifier
WALK_NESTED_ENUM(OmpReductionOperator, ProcedureOperator) // OMP reduction-identifier
WALK_NESTED_ENUM(OmpReductionOperator, BinaryOperator) // OMP reduction-identifier
WALK_NESTED_ENUM(OmpDependenceType, Type) // OMP dependence-type
WALK_NESTED_ENUM(OmpMapClause, Type) // OMP map-type
WALK_NESTED_ENUM(OmpScheduleClause, ScheduleType) // OMP schedule-type
WALK_NESTED_ENUM(OmpIfClause, DirectiveNameModifier) // OMP directive-modifier
#undef WALK_NESTED_ENUM
void Done() const { CHECK(indent_ == 0); }

View File

@@ -426,11 +426,6 @@ public:
NODE(parser::OmpClause, Uniform)
NODE(parser::OmpClause, Untied)
NODE(parser::OmpClause, UseDevicePtr)
NODE(parser, OmpDeclDirective)
NODE(parser::OmpDeclDirective, DeclareReduction)
NODE(parser::OmpDeclDirective, DeclareSimd)
NODE(parser::OmpDeclDirective, DeclareTarget)
NODE(parser::OmpDeclDirective, Threadprivate)
NODE(parser, OmpDefaultClause)
NODE(parser::OmpDefaultClause, Type)
NODE(parser, OmpDependClause)
@@ -474,7 +469,9 @@ public:
NODE(parser::OmpIfClause, DirectiveNameModifier)
NODE(parser, OmpScheduleClause)
NODE(parser::OmpScheduleClause, ScheduleType)
NODE(parser::OmpScheduleClause, Chunksize)
NODE(parser, OmpScheduleModifier)
NODE(parser::OmpScheduleModifier, Modifier1)
NODE(parser::OmpScheduleModifier, Modifier2)
NODE(parser, OmpScheduleModifierType)
NODE(parser::OmpScheduleModifierType, ModType)
NODE(parser, OmpMapClause)
@@ -497,7 +494,6 @@ public:
NODE(parser::OmpStandaloneDirective, Taskwait)
NODE(parser::OmpStandaloneDirective, Taskyield)
NODE(parser, OpenMPConstruct)
NODE(parser, OpenMPDeclConstruct)
NODE(parser, OpenMPLoopConstruct)
NODE(parser, OpenMPStandaloneConstruct)
NODE(parser, OmpReductionClause)