[flang-commits] [flang] [flang][OpenMP] Rewrite standalone `loop` (without `bind`) directives to `simd` (PR #122632)
Sergio Afonso via flang-commits
flang-commits at lists.llvm.org
Tue Jan 21 03:06:26 PST 2025
================
@@ -100,6 +117,62 @@ class GenericLoopConversionPattern
return result;
}
+ /// Rewrites standalone `loop` directives to equivalent `simd` constructs.
+ /// The reasoning behind this decision is that according to the spec (version
+ /// 5.2, section 11.7.1):
+ ///
+ /// "If the bind clause is not specified on a construct for which it may be
+ /// specified and the construct is closely nested inside a teams or parallel
+ /// construct, the effect is as if binding is teams or parallel. If none of
+ /// those conditions hold, the binding region is not defined."
+ ///
+ /// which means that standalone `loop` directives have undefined binding
+ /// region. Moreover, the spec says (in the next paragraph):
+ ///
+ /// "The specified binding region determines the binding thread set.
+ /// Specifically, if the binding region is a teams region, then the binding
+ /// thread set is the set of initial threads that are executing that region
+ /// while if the binding region is a parallel region, then the binding thread
+ /// set is the team of threads that are executing that region. If the binding
+ /// region is not defined, then the binding thread set is the encountering
+ /// thread."
+ ///
+ /// which means that the binding thread set for a standalone `loop` directive
+ /// is only the encountering thread.
+ ///
+ /// Since the encountering thread is the binding thread (set) for a
+ /// standalone `loop` directive, the best we can do in such case is to "simd"
+ /// the directive.
+ void rewriteToSimdLoop(mlir::omp::LoopOp loopOp,
+ mlir::ConversionPatternRewriter &rewriter) const {
+ loopOp.emitWarning("Detected standalone OpenMP `loop` directive, the "
+ "associated loop will be rewritten to `simd`.");
----------------
skatrak wrote:
Got it, thanks for the explanation.
https://github.com/llvm/llvm-project/pull/122632
More information about the flang-commits
mailing list