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
6 changes: 4 additions & 2 deletions flang/include/flang/Parser/openmp-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct ConstructId {
MAKE_CONSTR_ID(OpenMPDeclarativeAllocate, D::OMPD_allocate);
MAKE_CONSTR_ID(OpenMPDeclarativeAssumes, D::OMPD_assumes);
MAKE_CONSTR_ID(OpenMPDeclareReductionConstruct, D::OMPD_declare_reduction);
MAKE_CONSTR_ID(OpenMPDeclareSimdConstruct, D::OMPD_declare_simd);
MAKE_CONSTR_ID(OpenMPDeclareTargetConstruct, D::OMPD_declare_target);
MAKE_CONSTR_ID(OpenMPExecutableAllocate, D::OMPD_allocate);
MAKE_CONSTR_ID(OpenMPRequiresConstruct, D::OMPD_requires);
Expand All @@ -57,6 +56,10 @@ struct DirectiveNameScope {
return name;
}

static OmpDirectiveName GetOmpDirectiveName(const OmpDirectiveName &x) {
return x;
}

static OmpDirectiveName GetOmpDirectiveName(const OmpBeginLoopDirective &x) {
return x.DirName();
}
Expand Down Expand Up @@ -94,7 +97,6 @@ struct DirectiveNameScope {
} else if constexpr (std::is_same_v<T, OpenMPDeclarativeAllocate> ||
std::is_same_v<T, OpenMPDeclarativeAssumes> ||
std::is_same_v<T, OpenMPDeclareReductionConstruct> ||
std::is_same_v<T, OpenMPDeclareSimdConstruct> ||
std::is_same_v<T, OpenMPDeclareTargetConstruct> ||
std::is_same_v<T, OpenMPExecutableAllocate> ||
std::is_same_v<T, OpenMPRequiresConstruct>) {
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4987,9 +4987,9 @@ struct OpenMPDeclareReductionConstruct {
// 2.8.2 declare-simd -> DECLARE SIMD [(proc-name)] [declare-simd-clause[ [,]
// declare-simd-clause]...]
struct OpenMPDeclareSimdConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPDeclareSimdConstruct);
WRAPPER_CLASS_BOILERPLATE(
OpenMPDeclareSimdConstruct, OmpDirectiveSpecification);
CharBlock source;
std::tuple<Verbatim, std::optional<Name>, OmpClauseList> t;
};

// ref: [6.0:301-303]
Expand Down
5 changes: 3 additions & 2 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,8 +1836,9 @@ TYPE_PARSER(

// 2.8.2 Declare Simd construct
TYPE_PARSER(sourced(construct<OpenMPDeclareSimdConstruct>(
verbatim("DECLARE SIMD"_tok) || verbatim("DECLARE_SIMD"_tok),
maybe(parenthesized(name)), Parser<OmpClauseList>{})))
predicated(Parser<OmpDirectiveName>{},
IsDirective(llvm::omp::Directive::OMPD_declare_simd)) >=
Parser<OmpDirectiveSpecification>{})))

TYPE_PARSER(sourced( //
construct<OpenMPGroupprivate>(
Expand Down
7 changes: 3 additions & 4 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2573,11 +2573,10 @@ class UnparseVisitor {
Put("\n");
EndOpenMP();
}
void Unparse(const OpenMPDeclareSimdConstruct &y) {
void Unparse(const OpenMPDeclareSimdConstruct &x) {
BeginOpenMP();
Word("!$OMP DECLARE SIMD ");
Walk("(", std::get<std::optional<Name>>(y.t), ")");
Walk(std::get<OmpClauseList>(y.t));
Word("!$OMP ");
Walk(x.v);
Put("\n");
EndOpenMP();
}
Expand Down
33 changes: 26 additions & 7 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,6 @@ template <typename Checker> struct DirectiveSpellingVisitor {
checker_(std::get<parser::Verbatim>(x.t).source, Directive::OMPD_assumes);
return false;
}
bool Pre(const parser::OpenMPDeclareSimdConstruct &x) {
checker_(
std::get<parser::Verbatim>(x.t).source, Directive::OMPD_declare_simd);
return false;
}
bool Pre(const parser::OpenMPDeclareTargetConstruct &x) {
checker_(
std::get<parser::Verbatim>(x.t).source, Directive::OMPD_declare_target);
Expand Down Expand Up @@ -1356,8 +1351,32 @@ void OmpStructureChecker::Leave(const parser::OpenMPThreadprivate &x) {
}

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

const parser::OmpArgumentList &args{x.v.Arguments()};
if (args.v.empty()) {
return;
} else if (args.v.size() > 1) {
context_.Say(args.source,
"DECLARE_SIMD directive should have at most one argument"_err_en_US);
return;
}

const parser::OmpArgument &arg{args.v.front()};
if (auto *sym{GetArgumentSymbol(arg)}) {
if (!IsProcedure(*sym) && !IsFunction(*sym)) {
auto &msg{context_.Say(arg.source,
"The name '%s' should refer to a procedure"_err_en_US, sym->name())};
if (sym->test(Symbol::Flag::Implicit)) {
msg.Attach(arg.source,
"The name '%s' has been implicitly declared"_en_US, sym->name());
}
}
} else {
context_.Say(arg.source,
"The argument to the DECLARE_SIMD directive should be a procedure name"_err_en_US);
}
}

void OmpStructureChecker::Leave(const parser::OpenMPDeclareSimdConstruct &) {
Expand Down
7 changes: 4 additions & 3 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,10 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {

bool Pre(const parser::OpenMPDeclareSimdConstruct &x) {
PushContext(x.source, llvm::omp::Directive::OMPD_declare_simd);
const auto &name{std::get<std::optional<parser::Name>>(x.t)};
if (name) {
ResolveOmpName(*name, Symbol::Flag::OmpDeclareSimd);
for (const parser::OmpArgument &arg : x.v.Arguments().v) {
if (auto *object{omp::GetArgumentObject(arg)}) {
ResolveOmpObject(*object, Symbol::Flag::OmpDeclareSimd);
}
}
return true;
}
Expand Down
40 changes: 18 additions & 22 deletions flang/test/Parser/OpenMP/linear-clause.f90
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,16 @@ subroutine f03(x)

!UNPARSE: SUBROUTINE f03 (x)
!UNPARSE: INTEGER x
!UNPARSE: !$OMP DECLARE SIMD LINEAR(x: UVAL)
!UNPARSE: !$OMP DECLARE SIMD LINEAR(x: UVAL)
!UNPARSE: END SUBROUTINE

!PARSE-TREE: SpecificationPart
![...]
!PARSE-TREE: | DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct
!PARSE-TREE: | | Verbatim
!PARSE-TREE: | | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause
!PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x'
!PARSE-TREE: | | | Modifier -> OmpLinearModifier -> Value = Uval
!PARSE-TREE: | | | bool = 'true'
!PARSE-TREE: ExecutionPart -> Block
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct -> OmpDirectiveSpecification
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare simd
!PARSE-TREE: | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause
!PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x'
!PARSE-TREE: | | Modifier -> OmpLinearModifier -> Value = Uval
!PARSE-TREE: | | bool = 'true'
!PARSE-TREE: | Flags = None

subroutine f04(x)
integer :: x
Expand All @@ -104,17 +102,15 @@ subroutine f04(x)

!UNPARSE: SUBROUTINE f04 (x)
!UNPARSE: INTEGER x
!UNPARSE: !$OMP DECLARE SIMD LINEAR(x: UVAL, STEP(3_4))
!UNPARSE: !$OMP DECLARE SIMD LINEAR(x: UVAL, STEP(3_4))
!UNPARSE: END SUBROUTINE

!PARSE-TREE: SpecificationPart
![...]
!PARSE-TREE: | DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct
!PARSE-TREE: | | Verbatim
!PARSE-TREE: | | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause
!PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x'
!PARSE-TREE: | | | Modifier -> OmpLinearModifier -> Value = Uval
!PARSE-TREE: | | | Modifier -> OmpStepComplexModifier -> Scalar -> Integer -> Expr = '3_4'
!PARSE-TREE: | | | | LiteralConstant -> IntLiteralConstant = '3'
!PARSE-TREE: | | | bool = 'true'
!PARSE-TREE: ExecutionPart -> Block
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct -> OmpDirectiveSpecification
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare simd
!PARSE-TREE: | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause
!PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x'
!PARSE-TREE: | | Modifier -> OmpLinearModifier -> Value = Uval
!PARSE-TREE: | | Modifier -> OmpStepComplexModifier -> Scalar -> Integer -> Expr = '3_4'
!PARSE-TREE: | | | LiteralConstant -> IntLiteralConstant = '3'
!PARSE-TREE: | | bool = 'true'
!PARSE-TREE: | Flags = None
7 changes: 4 additions & 3 deletions flang/test/Parser/OpenMP/openmp6-directive-spellings.f90
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ subroutine f03
end

!UNPARSE: SUBROUTINE f03
!UNPARSE: !$OMP DECLARE SIMD
!UNPARSE: !$OMP DECLARE_SIMD
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct
!PARSE-TREE: | Verbatim
!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct -> OmpDirectiveSpecification
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare simd
!PARSE-TREE: | OmpClauseList ->
!PARSE-TREE: | Flags = None

subroutine f04
!$omp declare_target
Expand Down
22 changes: 22 additions & 0 deletions flang/test/Semantics/OpenMP/declare-simd.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=60

module m

!ERROR: The name 'x' should refer to a procedure
!$omp declare_simd(x)

!ERROR: DECLARE_SIMD directive should have at most one argument
!$omp declare_simd(f00, f01)

!ERROR: The argument to the DECLARE_SIMD directive should be a procedure name
!$omp declare_simd(v : integer)

contains

subroutine f00
end

subroutine f01
end

end module