[flang-commits] [flang] [llvm] [OpenMP] Introduce descriptors for directives, clause groups and sets (PR #229522)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Thu Oct 8 03:56:28 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;
+ F->second.Spelling = getOpenMPDirectiveName(D, V);
+ // The category should be the same for all of them (i.e. executable),
+ // the association of the last one is the association of the whole
+ // directive. Since the leafs are ordered from the outermost to the
+ // innermost it is safe to simply overwrite the non-set members each
+ // time.
+ F->second.Assoc = T.Assoc;
+ F->second.Cat = T.Cat;
+ F->second.Cls |= T.Cls;
+ F->second.ClsSets |= T.ClsSets;
+ }
+ }
+
+ auto At =
+ Compound.try_emplace(D, getOpenMPDirectiveName(D, MaxV), std::move(Det));
+ return At.first->second;
----------------
tblah wrote:
I think the descriptor will need to be returned by value. The dense map could be reallocated on any insertion: invalidating the references into its storage.
An alternative would be to return a smart pointer to the descriptor.
https://github.com/llvm/llvm-project/pull/229522
More information about the flang-commits
mailing list