1 //===-- OpenMP.cpp -- Open MP directive lowering --------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "flang/Lower/OpenMP.h"
14 #include "flang/Lower/Bridge.h"
15 #include "flang/Lower/FIRBuilder.h"
16 #include "flang/Lower/PFTBuilder.h"
17 #include "flang/Parser/parse-tree.h"
18 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
19 #include "llvm/Frontend/OpenMP/OMPConstants.h"
20 
21 #define TODO() llvm_unreachable("not yet implemented")
22 
23 static void genOMP(Fortran::lower::AbstractConverter &absConv,
24                    Fortran::lower::pft::Evaluation &eval,
25                    const Fortran::parser::OpenMPSimpleStandaloneConstruct
26                        &simpleStandaloneConstruct) {
27   const auto &directive =
28       std::get<Fortran::parser::OmpSimpleStandaloneDirective>(
29           simpleStandaloneConstruct.t);
30   switch (directive.v) {
31   default:
32     break;
33   case llvm::omp::Directive::OMPD_barrier:
34     absConv.getFirOpBuilder().create<mlir::omp::BarrierOp>(
35         absConv.getCurrentLocation());
36     break;
37   case llvm::omp::Directive::OMPD_taskwait:
38     TODO();
39   case llvm::omp::Directive::OMPD_taskyield:
40     TODO();
41   case llvm::omp::Directive::OMPD_target_enter_data:
42     TODO();
43   case llvm::omp::Directive::OMPD_target_exit_data:
44     TODO();
45   case llvm::omp::Directive::OMPD_target_update:
46     TODO();
47   case llvm::omp::Directive::OMPD_ordered:
48     TODO();
49   }
50 }
51 
52 static void
53 genOMP(Fortran::lower::AbstractConverter &absConv,
54        Fortran::lower::pft::Evaluation &eval,
55        const Fortran::parser::OpenMPStandaloneConstruct &standaloneConstruct) {
56   std::visit(
57       Fortran::common::visitors{
58           [&](const Fortran::parser::OpenMPSimpleStandaloneConstruct
59                   &simpleStandaloneConstruct) {
60             genOMP(absConv, eval, simpleStandaloneConstruct);
61           },
62           [&](const Fortran::parser::OpenMPFlushConstruct &flushConstruct) {
63             TODO();
64           },
65           [&](const Fortran::parser::OpenMPCancelConstruct &cancelConstruct) {
66             TODO();
67           },
68           [&](const Fortran::parser::OpenMPCancellationPointConstruct
69                   &cancellationPointConstruct) { TODO(); },
70       },
71       standaloneConstruct.u);
72 }
73 
74 void Fortran::lower::genOpenMPConstruct(
75     Fortran::lower::AbstractConverter &absConv,
76     Fortran::lower::pft::Evaluation &eval,
77     const Fortran::parser::OpenMPConstruct &ompConstruct) {
78 
79   std::visit(
80       common::visitors{
81           [&](const Fortran::parser::OpenMPStandaloneConstruct
82                   &standaloneConstruct) {
83             genOMP(absConv, eval, standaloneConstruct);
84           },
85           [&](const Fortran::parser::OpenMPSectionsConstruct
86                   &sectionsConstruct) { TODO(); },
87           [&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
88             TODO();
89           },
90           [&](const Fortran::parser::OpenMPBlockConstruct &blockConstruct) {
91             TODO();
92           },
93           [&](const Fortran::parser::OpenMPAtomicConstruct &atomicConstruct) {
94             TODO();
95           },
96           [&](const Fortran::parser::OpenMPCriticalConstruct
97                   &criticalConstruct) { TODO(); },
98       },
99       ompConstruct.u);
100 }
101 
102 void Fortran::lower::genOpenMPEndLoop(
103     Fortran::lower::AbstractConverter &, Fortran::lower::pft::Evaluation &,
104     const Fortran::parser::OmpEndLoopDirective &) {
105   TODO();
106 }
107