@@ -288,6 +288,14 @@ std::string stringify(const omp::DirectiveWithClauses &DWC) {
288
288
289
289
// --- Tests ----------------------------------------------------------
290
290
291
+ namespace red {
292
+ // Make it easier to construct reduction operators from built-in intrinsics.
293
+ omp::clause::ReductionOperator
294
+ makeOp (omp::clause::DefinedOperator::IntrinsicOperator Op) {
295
+ return omp::clause::ReductionOperator{omp::clause::DefinedOperator{Op}};
296
+ }
297
+ } // namespace red
298
+
291
299
namespace {
292
300
using namespace llvm ::omp;
293
301
@@ -699,6 +707,92 @@ TEST_F(OpenMPDecompositionTest, Order1) {
699
707
TEST_F (OpenMPDecompositionTest, Allocate1) {
700
708
omp::Object x{" x" };
701
709
710
+ // Allocate + firstprivate
711
+ omp::List<omp::Clause> Clauses{
712
+ {OMPC_allocate,
713
+ omp::clause::Allocate{{std::nullopt, std::nullopt, std::nullopt, {x}}}},
714
+ {OMPC_firstprivate, omp::clause::Firstprivate{{x}}},
715
+ };
716
+
717
+ omp::ConstructDecomposition Dec (AnyVersion, Helper, OMPD_parallel_sections,
718
+ Clauses);
719
+ ASSERT_EQ (Dec.output .size (), 2u );
720
+
721
+ std::string Dir0 = stringify (Dec.output [0 ]);
722
+ std::string Dir1 = stringify (Dec.output [1 ]);
723
+ ASSERT_EQ (Dir0, " parallel shared(x)" ); // (33)
724
+ ASSERT_EQ (Dir1, " sections firstprivate(x) allocate(, , , (x))" ); // (33)
725
+ }
726
+
727
+ TEST_F (OpenMPDecompositionTest, Allocate2) {
728
+ omp::Object x{" x" };
729
+ auto Add = red::makeOp (omp::clause::DefinedOperator::IntrinsicOperator::Add);
730
+
731
+ // Allocate + in_reduction
732
+ omp::List<omp::Clause> Clauses{
733
+ {OMPC_allocate,
734
+ omp::clause::Allocate{{std::nullopt, std::nullopt, std::nullopt, {x}}}},
735
+ {OMPC_in_reduction, omp::clause::InReduction{{{Add}, {x}}}},
736
+ };
737
+
738
+ omp::ConstructDecomposition Dec (AnyVersion, Helper, OMPD_target_parallel,
739
+ Clauses);
740
+ ASSERT_EQ (Dec.output .size (), 2u );
741
+
742
+ std::string Dir0 = stringify (Dec.output [0 ]);
743
+ std::string Dir1 = stringify (Dec.output [1 ]);
744
+ ASSERT_EQ (Dir0, " target in_reduction((3), (x)) allocate(, , , (x))" ); // (33)
745
+ ASSERT_EQ (Dir1, " parallel" ); // (33)
746
+ }
747
+
748
+ TEST_F (OpenMPDecompositionTest, Allocate3) {
749
+ omp::Object x{" x" };
750
+
751
+ // Allocate + linear
752
+ omp::List<omp::Clause> Clauses{
753
+ {OMPC_allocate,
754
+ omp::clause::Allocate{{std::nullopt, std::nullopt, std::nullopt, {x}}}},
755
+ {OMPC_linear,
756
+ omp::clause::Linear{{std::nullopt, std::nullopt, std::nullopt, {x}}}},
757
+ };
758
+
759
+ omp::ConstructDecomposition Dec (AnyVersion, Helper, OMPD_parallel_for,
760
+ Clauses);
761
+ ASSERT_EQ (Dec.output .size (), 2u );
762
+
763
+ std::string Dir0 = stringify (Dec.output [0 ]);
764
+ std::string Dir1 = stringify (Dec.output [1 ]);
765
+ // The "shared" clause is duplicated---this isn't harmful, but it
766
+ // should be fixed eventually.
767
+ ASSERT_EQ (Dir0, " parallel shared(x) shared(x)" ); // (33)
768
+ ASSERT_EQ (Dir1, " for linear(, , , (x)) firstprivate(x) lastprivate(, (x)) "
769
+ " allocate(, , , (x))" ); // (33)
770
+ }
771
+
772
+ TEST_F (OpenMPDecompositionTest, Allocate4) {
773
+ omp::Object x{" x" };
774
+
775
+ // Allocate + lastprivate
776
+ omp::List<omp::Clause> Clauses{
777
+ {OMPC_allocate,
778
+ omp::clause::Allocate{{std::nullopt, std::nullopt, std::nullopt, {x}}}},
779
+ {OMPC_lastprivate, omp::clause::Lastprivate{{std::nullopt, {x}}}},
780
+ };
781
+
782
+ omp::ConstructDecomposition Dec (AnyVersion, Helper, OMPD_parallel_sections,
783
+ Clauses);
784
+ ASSERT_EQ (Dec.output .size (), 2u );
785
+
786
+ std::string Dir0 = stringify (Dec.output [0 ]);
787
+ std::string Dir1 = stringify (Dec.output [1 ]);
788
+ ASSERT_EQ (Dir0, " parallel shared(x)" ); // (33)
789
+ ASSERT_EQ (Dir1, " sections lastprivate(, (x)) allocate(, , , (x))" ); // (33)
790
+ }
791
+
792
+ TEST_F (OpenMPDecompositionTest, Allocate5) {
793
+ omp::Object x{" x" };
794
+
795
+ // Allocate + private
702
796
omp::List<omp::Clause> Clauses{
703
797
{OMPC_allocate,
704
798
omp::clause::Allocate{{std::nullopt, std::nullopt, std::nullopt, {x}}}},
@@ -715,6 +809,27 @@ TEST_F(OpenMPDecompositionTest, Allocate1) {
715
809
ASSERT_EQ (Dir1, " sections private(x) allocate(, , , (x))" ); // (33)
716
810
}
717
811
812
+ TEST_F (OpenMPDecompositionTest, Allocate6) {
813
+ omp::Object x{" x" };
814
+ auto Add = red::makeOp (omp::clause::DefinedOperator::IntrinsicOperator::Add);
815
+
816
+ // Allocate + reduction
817
+ omp::List<omp::Clause> Clauses{
818
+ {OMPC_allocate,
819
+ omp::clause::Allocate{{std::nullopt, std::nullopt, std::nullopt, {x}}}},
820
+ {OMPC_reduction, omp::clause::Reduction{{std::nullopt, {Add}, {x}}}},
821
+ };
822
+
823
+ omp::ConstructDecomposition Dec (AnyVersion, Helper, OMPD_parallel_sections,
824
+ Clauses);
825
+ ASSERT_EQ (Dec.output .size (), 2u );
826
+
827
+ std::string Dir0 = stringify (Dec.output [0 ]);
828
+ std::string Dir1 = stringify (Dec.output [1 ]);
829
+ ASSERT_EQ (Dir0, " parallel shared(x)" ); // (33)
830
+ ASSERT_EQ (Dir1, " sections reduction(, (3), (x)) allocate(, , , (x))" ); // (33)
831
+ }
832
+
718
833
// REDUCTION
719
834
// [5.2:134:17-18]
720
835
// Directives: do, for, loop, parallel, scope, sections, simd, taskloop, teams
@@ -741,14 +856,6 @@ TEST_F(OpenMPDecompositionTest, Allocate1) {
741
856
// clause on the construct, then the effect is as if the list item in the
742
857
// reduction clause appears as a list item in a map clause with a map-type of
743
858
// tofrom.
744
- namespace red {
745
- // Make is easier to construct reduction operators from built-in intrinsics.
746
- omp::clause::ReductionOperator
747
- makeOp (omp::clause::DefinedOperator::IntrinsicOperator Op) {
748
- return omp::clause::ReductionOperator{omp::clause::DefinedOperator{Op}};
749
- }
750
- } // namespace red
751
-
752
859
TEST_F (OpenMPDecompositionTest, Reduction1) {
753
860
omp::Object x{" x" };
754
861
auto Add = red::makeOp (omp::clause::DefinedOperator::IntrinsicOperator::Add);
0 commit comments