[flang-commits] [flang] [llvm] [OpenMP] Introduce descriptors for directives, clause groups and sets (PR #229522)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Thu Oct 8 05:05:42 PDT 2026


================
@@ -95,9 +147,54 @@ Clauses descriptor::ModifierSet::getClauses(Version V) const {
 const descriptor::Clause &getDescriptor(Clause C) {
   return getClauseMap().at(C);
 }
+
+const descriptor::ClauseSet &getDescriptor(ClauseSet S) {
+  return getClauseSetMap().at(S);
+}
+
+const descriptor::Directive &getDescriptor(Directive D) {
+  ArrayRef<llvm::omp::Directive> Leafs = llvm::omp::getLeafConstructsOrSelf(D);
+  if (Leafs.size() == 1)
+    return getDirectiveMap().at(Leafs[0]);
+
+  static DenseMap<Directive, descriptor::Directive> Compound;
+  if (auto F = Compound.find(D); F != Compound.end())
+    return F->second;
+
+  // Combine details from all leafs into a single map and create a descriptor
+  // from it.
+  using Details = descriptor::details::Directive;
+  using DetailsMap = descriptor::DetailsMap<Details>;
+  DetailsMap Det;
+  llvm::omp::Version MaxV(0);
+
+  for (llvm::omp::Directive L : Leafs) {
+    const auto &Desc{getDescriptor(L)};
+    for (auto &[V, T] : Desc.getDetails()) {
+      MaxV = std::max(MaxV, V);
+      auto F = Det.insert({V, Details{}}).first;
----------------
kparzysz wrote:

This is used to establish the latest supported version.  It is then used to give the new descriptor a name.

Each descriptor has a name that is independent of the version. The motivation was to have a name that can be used in a diagnostic message that doesn't require version lookup. This works for things that don't have self-evident names, like clause modifiers. Directives and clauses have spellings (which can change from version to version), and diagnostics always use the spelling. However, since the "name" member still exists in the descriptor, we need to put something meaningful in it. The convention I assumed here is to use the latest spelling.

I added comments to the code to spell out the purpose of MaxV.

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


More information about the flang-commits mailing list