267 lines · plain
1! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck --ignore-case %s2! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s3 4!! Test multiple declarations for the same type, with different operations.5module mymod6 type :: tt7 real r8 end type tt9contains10 function mymax(a, b)11 type(tt) :: a, b, mymax12 if (a%r > b%r) then13 mymax = a14 else15 mymax = b16 end if17 end function mymax18end module mymod19 20program omp_examples21!CHECK-LABEL: PROGRAM omp_examples22 use mymod23 implicit none24 integer, parameter :: n = 10025 integer :: i26 type(tt) :: values(n), sum, prod, big, small27 28 !$omp declare reduction(+:tt:omp_out%r = omp_out%r + omp_in%r) initializer(omp_priv%r = 0)29!CHECK: !$OMP DECLARE REDUCTION(+:tt: omp_out%r = omp_out%r + omp_in%r) INITIALIZER(om&30!CHECK-NEXT: !$OMP&p_priv%r = 0)31 32!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification33!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction34!PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier35!PARSE-TREE: | | OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add36!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec37!PARSE-TREE: | | | Name = 'tt'38!PARSE-TREE: | | OmpCombinerExpression -> OmpStylizedInstance39!PARSE-TREE: | | | OmpStylizedDeclaration40!PARSE-TREE: | | | OmpStylizedDeclaration41!PARSE-TREE: | | | Instance -> AssignmentStmt = 'omp_out%r=omp_out%r+omp_in%r'42!PARSE-TREE: | | | | Variable = 'omp_out%r'43!PARSE-TREE: | | | | | Designator -> DataRef -> StructureComponent44!PARSE-TREE: | | | | | | DataRef -> Name = 'omp_out'45!PARSE-TREE: | | | | | | Name = 'r'46!PARSE-TREE: | | | | Expr = 'omp_out%r+omp_in%r'47!PARSE-TREE: | | | | | Add48!PARSE-TREE: | | | | | | Expr = 'omp_out%r'49!PARSE-TREE: | | | | | | | Designator -> DataRef -> StructureComponent50!PARSE-TREE: | | | | | | | | DataRef -> Name = 'omp_out'51!PARSE-TREE: | | | | | | | | Name = 'r'52!PARSE-TREE: | | | | | | Expr = 'omp_in%r'53!PARSE-TREE: | | | | | | | Designator -> DataRef -> StructureComponent54!PARSE-TREE: | | | | | | | | DataRef -> Name = 'omp_in'55!PARSE-TREE: | | | | | | | | Name = 'r'56!PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> OmpInitializerExpression -> OmpStylizedInstance57!PARSE-TREE: | | OmpStylizedDeclaration58!PARSE-TREE: | | OmpStylizedDeclaration59!PARSE-TREE: | | Instance -> AssignmentStmt = 'omp_priv%r=0._4'60!PARSE-TREE: | | | Variable = 'omp_priv%r'61!PARSE-TREE: | | | | Designator -> DataRef -> StructureComponent62!PARSE-TREE: | | | | | DataRef -> Name = 'omp_priv'63!PARSE-TREE: | | | | | Name = 'r'64!PARSE-TREE: | | | Expr = '0_4'65!PARSE-TREE: | | | | LiteralConstant -> IntLiteralConstant = '0'66!PARSE-TREE: | Flags = {}67 68 !$omp declare reduction(*:tt:omp_out%r = omp_out%r * omp_in%r) initializer(omp_priv%r = 1)69!CHECK-NEXT: !$OMP DECLARE REDUCTION(*:tt: omp_out%r = omp_out%r * omp_in%r) INITIALIZER(om&70!CHECK-NEXT: !$OMP&p_priv%r = 1)71 72!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification73!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction74!PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier75!PARSE-TREE: | | OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Multiply76!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec77!PARSE-TREE: | | | Name = 'tt'78!PARSE-TREE: | | OmpCombinerExpression -> OmpStylizedInstance79!PARSE-TREE: | | | OmpStylizedDeclaration80!PARSE-TREE: | | | OmpStylizedDeclaration81!PARSE-TREE: | | | Instance -> AssignmentStmt = 'omp_out%r=omp_out%r*omp_in%r'82!PARSE-TREE: | | | | Variable = 'omp_out%r'83!PARSE-TREE: | | | | | Designator -> DataRef -> StructureComponent84!PARSE-TREE: | | | | | | DataRef -> Name = 'omp_out'85!PARSE-TREE: | | | | | | Name = 'r'86!PARSE-TREE: | | | | Expr = 'omp_out%r*omp_in%r'87!PARSE-TREE: | | | | | Multiply88!PARSE-TREE: | | | | | | Expr = 'omp_out%r'89!PARSE-TREE: | | | | | | | Designator -> DataRef -> StructureComponent90!PARSE-TREE: | | | | | | | | DataRef -> Name = 'omp_out'91!PARSE-TREE: | | | | | | | | Name = 'r'92!PARSE-TREE: | | | | | | Expr = 'omp_in%r'93!PARSE-TREE: | | | | | | | Designator -> DataRef -> StructureComponent94!PARSE-TREE: | | | | | | | | DataRef -> Name = 'omp_in'95!PARSE-TREE: | | | | | | | | Name = 'r'96!PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> OmpInitializerExpression -> OmpStylizedInstance97!PARSE-TREE: | | OmpStylizedDeclaration98!PARSE-TREE: | | OmpStylizedDeclaration99!PARSE-TREE: | | Instance -> AssignmentStmt = 'omp_priv%r=1._4'100!PARSE-TREE: | | | Variable = 'omp_priv%r'101!PARSE-TREE: | | | | Designator -> DataRef -> StructureComponent102!PARSE-TREE: | | | | | DataRef -> Name = 'omp_priv'103!PARSE-TREE: | | | | | Name = 'r'104!PARSE-TREE: | | | Expr = '1_4'105!PARSE-TREE: | | | | LiteralConstant -> IntLiteralConstant = '1'106!PARSE-TREE: | Flags = {}107 108 !$omp declare reduction(max:tt:omp_out = mymax(omp_out, omp_in)) initializer(omp_priv%r = 0)109!CHECK-NEXT: !$OMP DECLARE REDUCTION(max:tt: omp_out = mymax(omp_out, omp_in)) INITIALIZER(&110!CHECK-NEXT: !$OMP&omp_priv%r = 0)111 112!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification113!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction114!PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier115!PARSE-TREE: | | OmpReductionIdentifier -> ProcedureDesignator -> Name = 'max'116!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec117!PARSE-TREE: | | | Name = 'tt'118!PARSE-TREE: | | OmpCombinerExpression -> OmpStylizedInstance119!PARSE-TREE: | | | OmpStylizedDeclaration120!PARSE-TREE: | | | OmpStylizedDeclaration121!PARSE-TREE: | | | Instance -> AssignmentStmt = 'omp_out=mymax(omp_out,omp_in)'122!PARSE-TREE: | | | | Variable = 'omp_out'123!PARSE-TREE: | | | | | Designator -> DataRef -> Name = 'omp_out'124!PARSE-TREE: | | | | Expr = 'mymax(omp_out,omp_in)'125!PARSE-TREE: | | | | | FunctionReference -> Call126!PARSE-TREE: | | | | | | ProcedureDesignator -> Name = 'mymax'127!PARSE-TREE: | | | | | | ActualArgSpec128!PARSE-TREE: | | | | | | | ActualArg -> Expr = 'omp_out'129!PARSE-TREE: | | | | | | | | Designator -> DataRef -> Name = 'omp_out'130!PARSE-TREE: | | | | | | ActualArgSpec131!PARSE-TREE: | | | | | | | ActualArg -> Expr = 'omp_in'132!PARSE-TREE: | | | | | | | | Designator -> DataRef -> Name = 'omp_in'133!PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> OmpInitializerExpression -> OmpStylizedInstance134!PARSE-TREE: | | OmpStylizedDeclaration135!PARSE-TREE: | | OmpStylizedDeclaration136!PARSE-TREE: | | Instance -> AssignmentStmt = 'omp_priv%r=0._4'137!PARSE-TREE: | | | Variable = 'omp_priv%r'138!PARSE-TREE: | | | | Designator -> DataRef -> StructureComponent139!PARSE-TREE: | | | | | DataRef -> Name = 'omp_priv'140!PARSE-TREE: | | | | | Name = 'r'141!PARSE-TREE: | | | Expr = '0_4'142!PARSE-TREE: | | | | LiteralConstant -> IntLiteralConstant = '0'143!PARSE-TREE: | Flags = {}144 145 !$omp declare reduction(min:tt:omp_out%r = min(omp_out%r, omp_in%r)) initializer(omp_priv%r = 1)146!CHECK-NEXT: !$OMP DECLARE REDUCTION(min:tt: omp_out%r = min(omp_out%r, omp_in%r)) INITIALI&147!CHECK-NEXT: !$OMP&ZER(omp_priv%r = 1)148 149!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareReductionConstruct -> OmpDirectiveSpecification150!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare reduction151!PARSE-TREE: | OmpArgumentList -> OmpArgument -> OmpReductionSpecifier152!PARSE-TREE: | | OmpReductionIdentifier -> ProcedureDesignator -> Name = 'min'153!PARSE-TREE: | | OmpTypeNameList -> OmpTypeName -> TypeSpec -> DerivedTypeSpec154!PARSE-TREE: | | | Name = 'tt'155!PARSE-TREE: | | OmpCombinerExpression -> OmpStylizedInstance156!PARSE-TREE: | | | OmpStylizedDeclaration157!PARSE-TREE: | | | OmpStylizedDeclaration158!PARSE-TREE: | | | Instance -> AssignmentStmt = 'omp_out%r=min(omp_out%r,omp_in%r)'159!PARSE-TREE: | | | | Variable = 'omp_out%r'160!PARSE-TREE: | | | | | Designator -> DataRef -> StructureComponent161!PARSE-TREE: | | | | | | DataRef -> Name = 'omp_out'162!PARSE-TREE: | | | | | | Name = 'r'163!PARSE-TREE: | | | | Expr = 'min(omp_out%r,omp_in%r)'164!PARSE-TREE: | | | | | FunctionReference -> Call165!PARSE-TREE: | | | | | | ProcedureDesignator -> Name = 'min'166!PARSE-TREE: | | | | | | ActualArgSpec167!PARSE-TREE: | | | | | | | ActualArg -> Expr = 'omp_out%r'168!PARSE-TREE: | | | | | | | | Designator -> DataRef -> StructureComponent169!PARSE-TREE: | | | | | | | | | DataRef -> Name = 'omp_out'170!PARSE-TREE: | | | | | | | | | Name = 'r'171!PARSE-TREE: | | | | | | ActualArgSpec172!PARSE-TREE: | | | | | | | ActualArg -> Expr = 'omp_in%r'173!PARSE-TREE: | | | | | | | | Designator -> DataRef -> StructureComponent174!PARSE-TREE: | | | | | | | | | DataRef -> Name = 'omp_in'175!PARSE-TREE: | | | | | | | | | Name = 'r'176!PARSE-TREE: | OmpClauseList -> OmpClause -> Initializer -> OmpInitializerClause -> OmpInitializerExpression -> OmpStylizedInstance177!PARSE-TREE: | | OmpStylizedDeclaration178!PARSE-TREE: | | OmpStylizedDeclaration179!PARSE-TREE: | | Instance -> AssignmentStmt = 'omp_priv%r=1._4'180!PARSE-TREE: | | | Variable = 'omp_priv%r'181!PARSE-TREE: | | | | Designator -> DataRef -> StructureComponent182!PARSE-TREE: | | | | | DataRef -> Name = 'omp_priv'183!PARSE-TREE: | | | | | Name = 'r'184!PARSE-TREE: | | | Expr = '1_4'185!PARSE-TREE: | | | | LiteralConstant -> IntLiteralConstant = '1'186!PARSE-TREE: | Flags = {}187 188 call random_number(values%r)189 190 sum%r = 0191 !$omp parallel do reduction(+:sum)192!CHECK: !$OMP PARALLEL DO REDUCTION(+: sum)193 194!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct195!PARSE-TREE: | OmpBeginLoopDirective196!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = parallel do197!PARSE-TREE: | | OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause198!PARSE-TREE: | | | Modifier -> OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Add199!PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'sum'200!PARSE-TREE: | | Flags = {}201!PARSE-TREE: | Block202!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct203 204 do i = 1, n205 sum%r = sum%r + values(i)%r206 end do207 208 prod%r = 1209 !$omp parallel do reduction(*:prod)210!CHECK: !$OMP PARALLEL DO REDUCTION(*: prod)211 212!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct213!PARSE-TREE: | OmpBeginLoopDirective214!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = parallel do215!PARSE-TREE: | | OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause216!PARSE-TREE: | | | Modifier -> OmpReductionIdentifier -> DefinedOperator -> IntrinsicOperator = Multiply217!PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'prod'218!PARSE-TREE: | | Flags = {}219!PARSE-TREE: | Block220!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct221 222 do i = 1, n223 prod%r = prod%r * (values(i)%r+0.6)224 end do225 226 big%r = 0227 !$omp parallel do reduction(max:big)228!CHECK: $OMP PARALLEL DO REDUCTION(max: big)229 230!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct231!PARSE-TREE: | OmpBeginLoopDirective232!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = parallel do233!PARSE-TREE: | | OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause234!PARSE-TREE: | | | Modifier -> OmpReductionIdentifier -> ProcedureDesignator -> Name = 'max'235!PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'big'236!PARSE-TREE: | | Flags = {}237!PARSE-TREE: | Block238!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct239 240 do i = 1, n241 big = mymax(values(i), big)242 end do243 244 small%r = 1245 !$omp parallel do reduction(min:small)246!CHECK: !$OMP PARALLEL DO REDUCTION(min: small)247 248!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct249!PARSE-TREE: | OmpBeginLoopDirective250!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = parallel do251!PARSE-TREE: | | OmpClauseList -> OmpClause -> Reduction -> OmpReductionClause252!PARSE-TREE: | | | Modifier -> OmpReductionIdentifier -> ProcedureDesignator -> Name = 'min'253!PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'small'254!PARSE-TREE: | | Flags = {}255!PARSE-TREE: | Block256!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct257 258 do i = 1, n259 small%r = min(values(i)%r, small%r)260 end do261 262 print *, values%r263 print *, "sum=", sum%r264 print *, "prod=", prod%r265 print *, "small=", small%r, " big=", big%r266end program omp_examples267