[flang-commits] [flang] [flang][OpenMP] Implement flexible OpenMP clause representation (PR #81621)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Tue Feb 20 06:15:22 PST 2024


================
@@ -142,6 +142,1122 @@ static void genNestedEvaluations(Fortran::lower::AbstractConverter &converter,
     converter.genEval(e);
 }
 
+//===----------------------------------------------------------------------===//
+// Clauses
+//===----------------------------------------------------------------------===//
+
+namespace detail {
+template <typename C> //
+llvm::omp::Clause getClauseIdForClass(C &&) {
+  using namespace Fortran;
+  using A = llvm::remove_cvref_t<C>; // A is referenced in OMP.inc
+  // The code included below contains a sequence of checks like the following
+  // for each OpenMP clause
+  //   if constexpr (std::is_same_v<A, parser::OmpClause::AcqRel>)
+  //     return llvm::omp::Clause::OMPC_acq_rel;
+  //   [...]
+#define GEN_FLANG_CLAUSE_PARSER_KIND_MAP
+#include "llvm/Frontend/OpenMP/OMP.inc"
+}
+} // namespace detail
+
+static llvm::omp::Clause getClauseId(const Fortran::parser::OmpClause &clause) {
+  return std::visit([](auto &&s) { return detail::getClauseIdForClass(s); },
+                    clause.u);
+}
+
+namespace omp {
+using namespace Fortran;
+using SomeType = evaluate::SomeType;
+using SomeExpr = semantics::SomeExpr;
+using MaybeExpr = semantics::MaybeExpr;
+
+template <typename T> //
+using List = std::vector<T>;
----------------
kparzysz wrote:

It used to be, but some classes that ended up in `List` were too large for SmallVector's default size estimation (200-something bytes), so I converted it to `std::vector`.
To elaborate: `SmallVector` takes two template arguments: type and initial size.  The initial size used to be mandatory, but at some point it was made optional, and the initial size was computed based on the type.  If the type exceeds some specific size, the estimation will no longer work, and the code will fail to compile.  Instead of adding a specific number, I just changed it to `std::vector`.  It can be changed back though.

https://github.com/llvm/llvm-project/pull/81621


More information about the flang-commits mailing list