mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 05:32:28 +08:00
[flang][OpenMP] Avoid extra newline when unparsing OmpReductionCombiner (#160200)
When the combiner contains an AssignmentStmt, the unparser for that will emit a newline after the assignment. Don't let it do that, unparse the assignment ourselves.
This commit is contained in:
committed by
GitHub
parent
0d08ffd22c
commit
31941d6476
@@ -2106,7 +2106,7 @@ public:
|
||||
Walk(std::get<OmpReductionIdentifier>(x.t));
|
||||
Put(":");
|
||||
Walk(std::get<OmpTypeNameList>(x.t));
|
||||
Walk(":", std::get<std::optional<OmpReductionCombiner>>(x.t));
|
||||
Walk(": ", std::get<std::optional<OmpReductionCombiner>>(x.t));
|
||||
}
|
||||
void Unparse(const llvm::omp::Directive &x) {
|
||||
unsigned ompVersion{langOpts_.OpenMPVersion};
|
||||
@@ -2500,7 +2500,16 @@ public:
|
||||
// Don't let the visitor go to the normal AssignmentStmt Unparse function,
|
||||
// it adds an extra newline that we don't want.
|
||||
if (const auto *assignment{std::get_if<AssignmentStmt>(&x.u)}) {
|
||||
Walk(assignment->t, "=");
|
||||
Walk(assignment->t, " = ");
|
||||
} else {
|
||||
Walk(x.u);
|
||||
}
|
||||
}
|
||||
void Unparse(const OmpReductionCombiner &x) {
|
||||
// Don't let the visitor go to the normal AssignmentStmt Unparse function,
|
||||
// it adds an extra newline that we don't want.
|
||||
if (const auto *assignment{std::get_if<AssignmentStmt>(&x.u)}) {
|
||||
Walk(assignment->t, " = ");
|
||||
} else {
|
||||
Walk(x.u);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ program omp_examples
|
||||
type(tt) :: values(n), sum, prod, big, small
|
||||
|
||||
!$omp declare reduction(+:tt:omp_out%r = omp_out%r + omp_in%r) initializer(omp_priv%r = 0)
|
||||
!CHECK: !$OMP DECLARE REDUCTION(+:tt: omp_out%r=omp_out%r+omp_in%r
|
||||
!CHECK-NEXT: ) INITIALIZER(omp_priv%r=0_4)
|
||||
!CHECK: !$OMP DECLARE REDUCTION(+:tt: omp_out%r = omp_out%r+omp_in%r) INITIALIZER(omp_priv%r = 0_4)
|
||||
|
||||
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification
|
||||
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction
|
||||
@@ -39,8 +38,7 @@ program omp_examples
|
||||
!PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv%r=0._4'
|
||||
|
||||
!$omp declare reduction(*:tt:omp_out%r = omp_out%r * omp_in%r) initializer(omp_priv%r = 1)
|
||||
!CHECK-NEXT: !$OMP DECLARE REDUCTION(*:tt: omp_out%r=omp_out%r*omp_in%r
|
||||
!CHECK-NEXT: ) INITIALIZER(omp_priv%r=1_4)
|
||||
!CHECK-NEXT: !$OMP DECLARE REDUCTION(*:tt: omp_out%r = omp_out%r*omp_in%r) INITIALIZER(omp_priv%r = 1_4)
|
||||
|
||||
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification
|
||||
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction
|
||||
@@ -52,8 +50,7 @@ program omp_examples
|
||||
!PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv%r=1._4'
|
||||
|
||||
!$omp declare reduction(max:tt:omp_out = mymax(omp_out, omp_in)) initializer(omp_priv%r = 0)
|
||||
!CHECK-NEXT: !$OMP DECLARE REDUCTION(max:tt: omp_out=mymax(omp_out,omp_in)
|
||||
!CHECK-NEXT: ) INITIALIZER(omp_priv%r=0_4)
|
||||
!CHECK-NEXT: !$OMP DECLARE REDUCTION(max:tt: omp_out = mymax(omp_out,omp_in)) INITIALIZER(omp_priv%r = 0_4)
|
||||
|
||||
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification
|
||||
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction
|
||||
@@ -65,8 +62,7 @@ program omp_examples
|
||||
!PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> AssignmentStmt = 'omp_priv%r=0._4'
|
||||
|
||||
!$omp declare reduction(min:tt:omp_out%r = min(omp_out%r, omp_in%r)) initializer(omp_priv%r = 1)
|
||||
!CHECK-NEXT: !$OMP DECLARE REDUCTION(min:tt: omp_out%r=min(omp_out%r,omp_in%r)
|
||||
!CHECK-NEXT: ) INITIALIZER(omp_priv%r=1_4)
|
||||
!CHECK-NEXT: !$OMP DECLARE REDUCTION(min:tt: omp_out%r = min(omp_out%r,omp_in%r)) INITIALIZER(omp_priv%r = 1_4)
|
||||
|
||||
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification
|
||||
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction
|
||||
|
||||
@@ -16,8 +16,7 @@ subroutine reduce_1 ( n, tts )
|
||||
type(tt) :: tts(n)
|
||||
type(tt2) :: tts2(n)
|
||||
|
||||
!CHECK: !$OMP DECLARE REDUCTION(+:tt: omp_out=tt(x=omp_out%x-omp_in%x,y=omp_out%y-omp_in%y)
|
||||
!CHECK: ) INITIALIZER(omp_priv=tt(x=0_4,y=0_4))
|
||||
!CHECK: !$OMP DECLARE REDUCTION(+:tt: omp_out = tt(x=omp_out%x-omp_in%x,y=omp_out%y-omp_in%y)) INITIALIZER(omp_priv = tt(x=0_4,y=0_4))
|
||||
|
||||
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification
|
||||
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction
|
||||
@@ -31,8 +30,7 @@ subroutine reduce_1 ( n, tts )
|
||||
!$omp declare reduction(+ : tt : omp_out = tt(omp_out%x - omp_in%x , omp_out%y - omp_in%y)) initializer(omp_priv = tt(0,0))
|
||||
|
||||
|
||||
!CHECK: !$OMP DECLARE REDUCTION(+:tt2: omp_out=tt2(x=omp_out%x-omp_in%x,y=omp_out%y-omp_in%y)
|
||||
!CHECK: ) INITIALIZER(omp_priv=tt2(x=0._8,y=0._8)
|
||||
!CHECK: !$OMP DECLARE REDUCTION(+:tt2: omp_out = tt2(x=omp_out%x-omp_in%x,y=omp_out%y-omp_in%y)) INITIALIZER(omp_priv = tt2(x=0._8,y=0._8)
|
||||
|
||||
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification
|
||||
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction
|
||||
|
||||
@@ -8,6 +8,6 @@ end
|
||||
|
||||
!CHECK: !DEF: /f00 (Subroutine) Subprogram
|
||||
!CHECK: subroutine f00
|
||||
!CHECK: !$omp declare reduction(fred:integer,real:omp_out = omp_in+omp_out)
|
||||
!CHECK: !$omp declare reduction(fred:integer,real: omp_out = omp_in+omp_out)
|
||||
!CHECK: end subroutine
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ function func(x, n, init)
|
||||
end subroutine initme
|
||||
end interface
|
||||
!$omp declare reduction(red_add:integer(4):omp_out=omp_out+omp_in) initializer(initme(omp_priv,0))
|
||||
!CHECK: !$OMP DECLARE REDUCTION(red_add:INTEGER(KIND=4_4): omp_out=omp_out+omp_in
|
||||
!CHECK: ) INITIALIZER(initme(omp_priv, 0_4))
|
||||
!CHECK: !$OMP DECLARE REDUCTION(red_add:INTEGER(KIND=4_4): omp_out = omp_out+omp_in) INITIALIZER(initme(omp_priv, 0_4))
|
||||
|
||||
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification
|
||||
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction
|
||||
@@ -60,8 +59,7 @@ end function func
|
||||
!CHECK-LABEL: program main
|
||||
program main
|
||||
integer :: my_var
|
||||
!CHECK: !$OMP DECLARE REDUCTION(my_add_red:INTEGER: omp_out=omp_out+omp_in
|
||||
!CHECK-NEXT: ) INITIALIZER(omp_priv=0_4)
|
||||
!CHECK: !$OMP DECLARE REDUCTION(my_add_red:INTEGER: omp_out = omp_out+omp_in) INITIALIZER(omp_priv = 0_4)
|
||||
|
||||
!$omp declare reduction (my_add_red : integer : omp_out = omp_out + omp_in) initializer (omp_priv=0)
|
||||
my_var = 0
|
||||
|
||||
@@ -105,8 +105,8 @@ end
|
||||
!UNPARSE: TYPE :: tt2
|
||||
!UNPARSE: REAL :: x
|
||||
!UNPARSE: END TYPE
|
||||
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE REDUCTION(+:tt1,tt2: omp_out%x=omp_in%x+omp_out%x
|
||||
!UNPARSE: ))
|
||||
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE REDUCTION(+:tt1,tt2: omp_out%x = omp_in%x+omp_out%x)&
|
||||
!UNPARSE: !$OMP&)
|
||||
!UNPARSE: END SUBROUTINE
|
||||
|
||||
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
|
||||
|
||||
@@ -79,8 +79,7 @@ end
|
||||
!UNPARSE: TYPE :: t
|
||||
!UNPARSE: INTEGER :: x
|
||||
!UNPARSE: END TYPE
|
||||
!UNPARSE: !$OMP DECLARE_REDUCTION(+:t: omp_out%x=omp_out%x+omp_in%x
|
||||
!UNPARSE: )
|
||||
!UNPARSE: !$OMP DECLARE_REDUCTION(+:t: omp_out%x = omp_out%x+omp_in%x)
|
||||
!UNPARSE: END SUBROUTINE
|
||||
|
||||
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
!type::t1
|
||||
!integer(4)::val
|
||||
!endtype
|
||||
!!$OMP DECLARE REDUCTION(*:t1:omp_out = omp_out*omp_in) INITIALIZER(omp_priv=t1&
|
||||
!!$OMP&(1))
|
||||
!!$OMP DECLARE REDUCTION(*:t1:omp_out=omp_out*omp_in)INITIALIZER(omp_priv=&
|
||||
!!$OMP&t1(1))
|
||||
!!$OMP METADIRECTIVE OTHERWISE(DECLARE REDUCTION(+:INTEGER))
|
||||
!!$OMP DECLARE REDUCTION(.fluffy.:t1:omp_out = omp_out.fluffy.omp_in) INITIALIZ&
|
||||
!!$OMP&ER(omp_priv=t1(0))
|
||||
!!$OMP DECLARE REDUCTION(.mul.:t1:omp_out = omp_out.mul.omp_in) INITIALIZER(omp&
|
||||
!!$OMP&_priv=t1(1))
|
||||
!!$OMP DECLARE REDUCTION(.fluffy.:t1:omp_out=omp_out.fluffy.omp_in)INITIALI&
|
||||
!!$OMP&ZER(omp_priv=t1(0))
|
||||
!!$OMP DECLARE REDUCTION(.mul.:t1:omp_out=omp_out.mul.omp_in)INITIALIZER(om&
|
||||
!!$OMP&p_priv=t1(1))
|
||||
!interface operator(.mul.)
|
||||
!procedure::mul
|
||||
!end interface
|
||||
|
||||
Reference in New Issue
Block a user