[flang-commits] [flang] [flang][OpenMP][NFC] Extract enclosing-construct trait collection helper (PR #203924)
Sergio Afonso via flang-commits
flang-commits at lists.llvm.org
Mon Jun 15 09:13:34 PDT 2026
================
@@ -1437,6 +1437,31 @@ bool FlangOMPContext::matchesISATrait(llvm::StringRef rawString) const {
return targetFeatures.contains(("+" + rawString).str());
}
+void collectEnclosingConstructTraits(
+ fir::FirOpBuilder &builder,
+ llvm::SmallVectorImpl<llvm::omp::TraitProperty> &constructTraits) {
+ // Collect enclosing OpenMP operations so variants chosen by an outer
+ // metadirective are part of this metadirective's context. For example, an
+ // inner metadirective inside `target` and an outer-selected `parallel` must
+ // be able to match construct={target, parallel}. The final reverse yields
+ // outermost-to-innermost order as required by OMPContext.
+ for (mlir::Operation *op = builder.getInsertionBlock()->getParentOp(); op;
+ op = op->getParentOp()) {
+ if (mlir::isa<mlir::omp::WsloopOp>(op))
+ constructTraits.push_back(llvm::omp::TraitProperty::construct_for_for);
+ if (mlir::isa<mlir::omp::ParallelOp>(op))
+ constructTraits.push_back(
+ llvm::omp::TraitProperty::construct_parallel_parallel);
+ if (mlir::isa<mlir::omp::TeamsOp>(op))
+ constructTraits.push_back(
+ llvm::omp::TraitProperty::construct_teams_teams);
+ if (mlir::isa<mlir::omp::TargetOp>(op))
+ constructTraits.push_back(
+ llvm::omp::TraitProperty::construct_target_target);
+ }
+ std::reverse(constructTraits.begin(), constructTraits.end());
----------------
skatrak wrote:
Nit: I don't have a strong opinion on this, but it seems like making this part of the function itself would cause it to be more expensive even if you use it in a context where you don't care about the order or you want the exact opposite. In my opinion, returning the innermost-to-outermost order gives more flexibility without performance penalties.
https://github.com/llvm/llvm-project/pull/203924
More information about the flang-commits
mailing list