Skip to content

Commit 203270a

Browse files
[FLANG][OpenMP]Add support for ALIGN clause on OMP ALLOCATE
This is trivially additional support for the existing ALLOCATE directive, which allows an ALIGN clause. The ALLOCATE directive is currently not implemented, so this is just addding the necessary parser parts to allow the compiler to not say "Huh? I don't get this" [or "Expected OpenMP construct"] when it encounters the ALIGN clause. Some parser testing is updated and a new todo test, just in case the feature of align clause is not supported by the initial support for ALLOCATE.
1 parent 4a0d53a commit 203270a

File tree

7 files changed

+54
-1
lines changed

7 files changed

+54
-1
lines changed

flang/include/flang/Parser/dump-parse-tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ class ParseTreeDumper {
486486
NODE(parser, OmpAffinityClause)
487487
NODE(OmpAffinityClause, Modifier)
488488
NODE(parser, OmpAlignment)
489+
NODE(parser, OmpAlignClause)
489490
NODE(parser, OmpAlignedClause)
490491
NODE(OmpAlignedClause, Modifier)
491492
NODE(parser, OmpAtClause)

flang/include/flang/Parser/parse-tree.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,6 +3752,11 @@ struct OmpAffinityClause {
37523752
std::tuple<MODIFIERS(), OmpObjectList> t;
37533753
};
37543754

3755+
// Ref: 5.2: [174]
3756+
struct OmpAlignClause {
3757+
WRAPPER_CLASS_BOILERPLATE(OmpAlignClause, ScalarIntExpr);
3758+
};
3759+
37553760
// Ref: [4.5:72-81], [5.0:110-119], [5.1:134-143], [5.2:169-170]
37563761
//
37573762
// aligned-clause ->

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ TYPE_PARSER(construct<OmpBindClause>(
567567
"TEAMS" >> pure(OmpBindClause::Binding::Teams) ||
568568
"THREAD" >> pure(OmpBindClause::Binding::Thread)))
569569

570+
TYPE_PARSER(construct<OmpAlignClause>(scalarIntExpr))
571+
570572
TYPE_PARSER(construct<OmpAtClause>(
571573
"EXECUTION" >> pure(OmpAtClause::ActionTime::Execution) ||
572574
"COMPILATION" >> pure(OmpAtClause::ActionTime::Compilation)))
@@ -582,6 +584,8 @@ TYPE_PARSER(
582584
"ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) ||
583585
"AFFINITY" >> construct<OmpClause>(construct<OmpClause::Affinity>(
584586
parenthesized(Parser<OmpAffinityClause>{}))) ||
587+
"ALIGN" >> construct<OmpClause>(construct<OmpClause::Align>(
588+
parenthesized(Parser<OmpAlignClause>{}))) ||
585589
"ALIGNED" >> construct<OmpClause>(construct<OmpClause::Aligned>(
586590
parenthesized(Parser<OmpAlignedClause>{}))) ||
587591
"ALLOCATE" >> construct<OmpClause>(construct<OmpClause::Allocate>(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! This test checks lowering of OpenMP allocate Directive with align clause.
2+
3+
// RUN: not flang -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
4+
5+
program main
6+
integer :: x
7+
8+
// CHECK: not yet implemented: OpenMPDeclarativeAllocate
9+
!$omp allocate(x) align(32)
10+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
! REQUIRES: openmp_runtime
2+
3+
! RUN: %flang_fc1 %openmp_flags -fopenmp-version=51 -fdebug-dump-parse-tree %s | FileCheck %s
4+
! RUN: %flang_fc1 %openmp_flags -fdebug-unparse -fopenmp-version=51 %s | FileCheck %s --check-prefix="UNPARSE"
5+
! Ensures associated declarative OMP allocations are nested in their
6+
! corresponding executable allocate directive
7+
8+
program allocate_tree
9+
use omp_lib
10+
integer, allocatable :: j
11+
!$omp allocate(j) align(16)
12+
allocate(j)
13+
end program allocate_tree
14+
15+
!CHECK: | | DeclarationConstruct -> SpecificationConstruct -> TypeDeclarationStmt
16+
!CHECK-NEXT: | | | DeclarationTypeSpec -> IntrinsicTypeSpec -> IntegerTypeSpec ->
17+
!CHECK-NEXT: | | | AttrSpec -> Allocatable
18+
!CHECK-NEXT: | | | EntityDecl
19+
!CHECK-NEXT: | | | | Name = 'j'
20+
21+
22+
!CHECK: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPExecutableAllocate
23+
!CHECK-NEXT: | | | Verbatim
24+
!CHECK-NEXT: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'j'
25+
!CHECK-NEXT: | | | OmpClauseList -> OmpClause -> Align -> OmpAlignClause -> Scalar -> Integer -> Expr = '16_4'
26+
!CHECK-NEXT: | | | | LiteralConstant -> IntLiteralConstant = '16'
27+
!CHECK-NEXT: | | | AllocateStmt
28+
29+
!UNPARSE: !$OMP ALLOCATE (j) ALIGN(16_4)
30+
!UNPARSE-NEXT: ALLOCATE(j)

flang/test/Parser/OpenMP/allocate-unparse.f90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ program allocate_unparse
55
use omp_lib
66

77
real, dimension (:,:), allocatable :: darray
8-
integer :: a, b, m, n, t, x, y, z
8+
integer :: a, b, j, m, n, t, x, y, z
99

1010
! 2.11.3 declarative allocate
1111

@@ -25,6 +25,7 @@ program allocate_unparse
2525
!$omp allocate(z) allocator(omp_default_mem_alloc)
2626
!$omp allocate(m) allocator(omp_default_mem_alloc)
2727
!$omp allocate(n)
28+
!$omp allocate(j) align(16)
2829
allocate ( darray(z, t) )
2930

3031
end program allocate_unparse
@@ -41,4 +42,5 @@ end program allocate_unparse
4142
!CHECK:!$OMP ALLOCATE (z) ALLOCATOR(omp_default_mem_alloc)
4243
!CHECK:!$OMP ALLOCATE (m) ALLOCATOR(omp_default_mem_alloc)
4344
!CHECK:!$OMP ALLOCATE (n)
45+
!CHECK:!$OMP ALLOCATE (j) ALIGN(16)
4446
!CHECK:ALLOCATE(darray(z,t))

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def OMPC_Affinity : Clause<"affinity"> {
4949
}
5050
def OMPC_Align : Clause<"align"> {
5151
let clangClass = "OMPAlignClause";
52+
let flangClass = "OmpAlignClause";
5253
}
5354
def OMPC_Aligned : Clause<"aligned"> {
5455
let clangClass = "OMPAlignedClause";

0 commit comments

Comments
 (0)