[llvm-branch-commits] [clang] [llvm] [Clang][OpenMP] Serialize lockstep warp lanes across omp_set_lock regions (PR #242480)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Nov 13 12:50:10 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: Julian Brown (jtb20)
<details>
<summary>Changes</summary>
Where the threads of a wavefront/warp run in lockstep (as for many typical GPUs), multiple lanes reaching an omp_set_lock call may deadlock (or trap, on AMDGPU) if they contend for a lock. This is actually permitted by the spec (OpenMP 6.0, 1.2 Execution Model: "A program that relies on concurrent execution of such diverging code paths for the purposes of synchronization may deadlock.").
However, in some common cases we can do better. This patch allows set/unset pairs to work as long as their lock expressions are the same, they are in the same compound statement, and no intervening code has control-flow that enters or leaves the sequence or various other constructs. I.e.:
omp_set_lock(L); ... omp_unset_lock(L);
is emitted through the lane serialization that OpenMPIRBuilder provides for critical regions, so that each lane takes and releases the lock in turn. This is done only where every lane is certain to release every lock it takes before the next lane's turn.
A new warning (with explanatory note) is added in Sema for patterns which can confidently be predicted to allow multiple lanes of a wavefront to reach an omp_set_lock when the serialization *cannot* be done. The name is -Wopenmp-lockstep-lock.
This patch is a little invasive, and not actually required for OpenMP conformance (at least as of 6.0). As such the previous patches can be committed without it if desired.
Assisted-By: Claude
---
Patch is 55.48 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/242480.diff
18 Files Affected:
- (modified) clang/docs/OpenMPSupport.md (+24)
- (modified) clang/docs/ReleaseNotes.md (+8)
- (added) clang/include/clang/AST/OpenMPLockSequence.h (+87)
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+2-1)
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+18)
- (modified) clang/include/clang/Sema/SemaOpenMP.h (+12)
- (modified) clang/lib/AST/CMakeLists.txt (+1)
- (added) clang/lib/AST/OpenMPLockSequence.cpp (+177)
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.h (+10)
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+15)
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.h (+6)
- (modified) clang/lib/CodeGen/CGStmt.cpp (+12-1)
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+165)
- (modified) clang/lib/Sema/SemaStmt.cpp (+4-1)
- (added) clang/test/OpenMP/amdgcn_lock_lane_serialization.c (+337)
- (added) clang/test/OpenMP/amdgcn_lock_lane_serialization.cpp (+158)
- (added) clang/test/OpenMP/target_lock_lane_warning.cpp (+233)
- (added) offload/test/offloading/target_lock_lanes.c (+115)
``````````diff
diff --git a/clang/docs/OpenMPSupport.md b/clang/docs/OpenMPSupport.md
index 0978d7269d0ca..0582be3eea527 100644
--- a/clang/docs/OpenMPSupport.md
+++ b/clang/docs/OpenMPSupport.md
@@ -84,6 +84,30 @@ between the threads in the parallel regions. Often, the optimizer is able to
reduce the cost of `Generic` mode to the level of `Cuda` mode, but the flag,
as well as other assumption flags, can be used for tuning.
+### Locks and critical regions on GPUs
+
+On a GPU, the threads of a warp (an AMD GPU wavefront) may execute a single
+instruction stream, so in OpenMP 6.0 terms a warp is a *progress unit*.
+Divergent threads in such a progress unit that synchronize with each other, e.g.
+by calling `omp_set_lock(lock)`, may deadlock. A `parallel` on the GPU behaves
+as if it had a `safesync` clause whose width is the warp size.
+
+- A `critical` region is run by the threads of each warp one at a time.
+- A sequence `omp_set_lock(lock); ...; omp_unset_lock(lock);` is also run one
+ thread at a time, if
+ - both calls are statements of the same block, with the same lock expression;
+ - the code between them can be entered only at the start and left only at
+ the end, contains no OpenMP directive and declares nothing at its top level;
+ - it uses the lock routines only in further such pairs, properly nested, at
+ the top level of the block.
+- Any other `omp_set_lock` that several threads of a warp reach together may
+ deadlock if they contend for the same lock. On AMD GPUs the device runtime
+ traps instead when they reach it together, with an explanatory message.
+
+Clang warns (`-Wopenmp-lockstep-lock`) about each call to `omp_set_lock` that
+cannot be handled this way and that is within a construct where multiple lanes
+may be active.
+
### Features not supported or with limited support for Cuda devices
- Cancellation constructs are not supported.
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 219e9925b3f00..12cd387af0651 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1690,6 +1690,14 @@ The `alpha.cplusplus.UseAfterLifetimeEnd` checker was renamed to `alpha.core.Use
another lane of the same wavefront spins for it; `omp_set_lock` traps in
that case rather than hang.
+- On GPUs, whose threads of a warp may run in lockstep, where
+ `omp_set_lock(lock)` and the matching `omp_unset_lock(lock)` are in the same
+ block, with code between them that can only be entered at the start and left
+ at the end, the threads of a warp now run that sequence one at a time. This
+ makes the common pattern of every thread taking the same lock work. When an
+ `omp_set_lock` cannot be handled this way and several threads of a warp may
+ reach it together, a new warning `-Wopenmp-lockstep-lock` explains the reason.
+
### SYCL Support
- On a `spirv32-unknown-unknown` or `spirv64-unknown-unknown` offload target,
diff --git a/clang/include/clang/AST/OpenMPLockSequence.h b/clang/include/clang/AST/OpenMPLockSequence.h
new file mode 100644
index 0000000000000..4757103756819
--- /dev/null
+++ b/clang/include/clang/AST/OpenMPLockSequence.h
@@ -0,0 +1,87 @@
+//===- OpenMPLockSequence.h - OpenMP lock sequences in a block --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Where the threads of a wavefront run in lockstep, a thread that takes an
+// OpenMP lock cannot release it while another thread of its wavefront spins for
+// the same lock. A compound statement containing
+//
+// omp_set_lock(L); ... omp_unset_lock(L);
+//
+// can instead be run by the threads of a wavefront one at a time, provided that
+// each thread releases every lock it takes before the next thread's turn. The
+// analysis in this file is used both by code generation and semantic analysis;
+// the latter warns about omp_set_lock cases that cannot be handled like this.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_OPENMPLOCKSEQUENCE_H
+#define LLVM_CLANG_AST_OPENMPLOCKSEQUENCE_H
+
+#include "clang/Basic/LLVM.h"
+
+namespace clang {
+
+class ASTContext;
+class CallExpr;
+class Decl;
+class Stmt;
+
+/// Reasons why an omp_set_lock ... omp_unset_lock sequence might be rejected.
+/// Keep this list aligned with the %select in
+/// warn_omp_lock_not_lane_serialized.
+enum class OMPLockSequenceRejection : unsigned {
+ /// No matching omp_unset_lock follows it in the same compound statement.
+ NoUnset,
+ /// Control can enter or leave the code before the matching omp_unset_lock
+ /// other than at its ends.
+ Escape,
+ /// A lock routine is used before the matching omp_unset_lock other than in
+ /// properly nested pairs at the top level of the compound statement.
+ OtherLockUse,
+ /// An OpenMP directive comes before the matching omp_unset_lock.
+ Directive,
+ /// A variable is declared before the matching omp_unset_lock.
+ Declaration,
+ /// The lock expression has side effects.
+ SideEffects,
+ /// The omp_set_lock statement is labelled.
+ Labelled,
+ /// The omp_set_lock call is not a statement of a compound statement.
+ NotInBlock,
+};
+
+/// The result of looking for a lock sequence at the start of some statements.
+struct OMPLockSequence {
+ /// The omp_set_lock call made by the first statement, if it makes one.
+ const CallExpr *SetCall = nullptr;
+ /// The number of statements in the sequence, or 0 if there is none.
+ unsigned Length = 0;
+ /// Why there is no sequence, if SetCall is set and Length is 0.
+ OMPLockSequenceRejection Rejection = OMPLockSequenceRejection::NoUnset;
+};
+
+/// Returns true if \p D is one of the OpenMP lock routines that set, unset or
+/// test a lock.
+bool isOMPLockRoutine(const Decl *D);
+
+/// Returns true if \p CE calls omp_set_lock.
+bool isOMPSetLockCall(const CallExpr *CE);
+
+/// Looks for a sequence `omp_set_lock(L); ... omp_unset_lock(L);` that the
+/// threads of a warp can run one at a time at the start of \p Stmts, the
+/// statements of a compound statement not yet considered. The sequence must use
+/// the same side-effect-free lock expression in both calls; the statements in
+/// between must be enterable only at the start and leavable only at the end,
+/// declare nothing, contain no OpenMP directive, and use the lock routines only
+/// in further such pairs, properly nested, among themselves.
+OMPLockSequence matchOMPLockSequence(ArrayRef<Stmt *> Stmts,
+ const ASTContext &Ctx);
+
+} // namespace clang
+
+#endif // LLVM_CLANG_AST_OPENMPLOCKSEQUENCE_H
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 1ac09a3b75ca8..00a89383a2cc0 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1803,11 +1803,12 @@ def OpenMPPre51Compat : DiagGroup<"pre-openmp-51-compat">;
def OpenMP51Ext : DiagGroup<"openmp-51-extensions">;
def OpenMPExtensions : DiagGroup<"openmp-extensions">;
def OpenMPTargetException : DiagGroup<"openmp-target-exception">;
+def OpenMPLockstepLock : DiagGroup<"openmp-lockstep-lock">;
def OpenMPFuture : DiagGroup<"openmp-future">;
def OpenMP : DiagGroup<"openmp", [
SourceUsesOpenMP, OpenMPClauses, OpenMPLoopForm, OpenMPTarget,
OpenMPMapping, OpenMP51Ext, OpenMPExtensions, OpenMPTargetException,
- OpenMPFuture
+ OpenMPFuture, OpenMPLockstepLock
]>;
// OpenACC warnings.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d4b29f573da5d..e86b2ac6cd9f7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12395,6 +12395,24 @@ def warn_omp_declare_target_local_nohost
: Warning<"'device_type(nohost)' is not yet supported with 'local' clause; "
"treating as 'device_type(any)'">,
InGroup<OpenMPTarget>;
+def warn_omp_lock_not_lane_serialized : Warning<
+ "'omp_set_lock' may be reached by several threads of a warp at once, but "
+ "they cannot be made to take the lock one at a time because "
+ // The cases follow OMPLockSequenceRejection.
+ "%select{no matching 'omp_unset_lock' follows it in the same block|"
+ "control can enter or leave the locked code other than at its ends|"
+ "the locked code uses a lock routine other than in properly nested "
+ "set/unset pairs|"
+ "the locked code contains an OpenMP directive|"
+ "the locked code declares a variable|"
+ "the lock expression has side effects|"
+ "the call is labelled; put the locked code in a block of its own|"
+ "the call is not a statement of its own in a block}0; threads of a warp "
+ "that contend for the lock will trap or hang">,
+ InGroup<OpenMPLockstepLock>;
+def note_omp_lock_lockstep_context : Note<
+ "threads of a warp may execute this '#pragma omp %0' region together; use "
+ "'single', 'masked' or 'critical' to run code on one thread at a time">;
def warn_omp_not_in_target_context : Warning<
"declaration is not declared in any declare target region">,
InGroup<OpenMPTarget>;
diff --git a/clang/include/clang/Sema/SemaOpenMP.h b/clang/include/clang/Sema/SemaOpenMP.h
index a8a291d02722c..6f4e5df82b173 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -29,6 +29,7 @@
#include "clang/Sema/Ownership.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/Frontend/OpenMP/OMP.h.inc"
#include "llvm/Frontend/OpenMP/OMPConstants.h"
#include <array>
@@ -76,6 +77,12 @@ class SemaOpenMP : public SemaBase {
unsigned DiagID,
const FunctionDecl *FD);
+ /// Where the threads of a warp run in lockstep on the device, warns about
+ /// each call to omp_set_lock in the compound statement \p CS that several
+ /// threads of a warp may reach together, but that does not begin a sequence
+ /// they can be made to run one at a time (see OpenMPLockSequence.h).
+ void diagnoseLockstepLocks(const CompoundStmt *CS);
+
/// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current
/// context is "used as host code".
///
@@ -1542,6 +1549,11 @@ class SemaOpenMP : public SemaBase {
private:
void *VarDataSharingAttributesStack;
+ /// Locations of calls to omp_set_lock already diagnosed by
+ /// diagnoseLockstepLocks, so that each template instantiation does not
+ /// repeat the warning.
+ llvm::DenseSet<SourceLocation> DiagnosedLockstepLockCalls;
+
/// Number of nested '#pragma omp declare target' directives.
SmallVector<DeclareTargetContextInfo, 4> DeclareTargetNesting;
diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 5d910d71d7d74..0a9f2a78b22f4 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -110,6 +110,7 @@ add_clang_library(clangAST
ODRHash.cpp
OpenACCClause.cpp
OpenMPClause.cpp
+ OpenMPLockSequence.cpp
OSLog.cpp
ParentMap.cpp
PrintfFormatString.cpp
diff --git a/clang/lib/AST/OpenMPLockSequence.cpp b/clang/lib/AST/OpenMPLockSequence.cpp
new file mode 100644
index 0000000000000..0979075aa684c
--- /dev/null
+++ b/clang/lib/AST/OpenMPLockSequence.cpp
@@ -0,0 +1,177 @@
+//===- OpenMPLockSequence.cpp - OpenMP lock sequences in a block ----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/OpenMPLockSequence.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/StmtCXX.h"
+#include "clang/AST/StmtObjC.h"
+#include "clang/AST/StmtOpenMP.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringSwitch.h"
+#include <optional>
+
+using namespace clang;
+
+bool clang::isOMPLockRoutine(const Decl *D) {
+ const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
+ if (!FD || !FD->isExternC() || !FD->getIdentifier())
+ return false;
+ return llvm::StringSwitch<bool>(FD->getName())
+ .Cases({"omp_set_lock", "omp_unset_lock", "omp_test_lock",
+ "omp_set_nest_lock", "omp_unset_nest_lock", "omp_test_nest_lock"},
+ true)
+ .Default(false);
+}
+
+bool clang::isOMPSetLockCall(const CallExpr *CE) {
+ const FunctionDecl *FD = CE->getDirectCallee();
+ return isOMPLockRoutine(FD) && FD->getName() == "omp_set_lock";
+}
+
+/// If \p S is the statement `Name(Arg);` calling the OpenMP lock routine
+/// \p Name, return the call.
+static const CallExpr *getLockCall(const Stmt *S, StringRef Name) {
+ const auto *E = dyn_cast<Expr>(S);
+ if (!E)
+ return nullptr;
+ const auto *CE = dyn_cast<CallExpr>(E->IgnoreImplicit()->IgnoreParens());
+ if (!CE || CE->getNumArgs() != 1)
+ return nullptr;
+ const FunctionDecl *FD = CE->getDirectCallee();
+ if (!isOMPLockRoutine(FD) || FD->getName() != Name)
+ return nullptr;
+ return CE;
+}
+
+/// If \p S is the statement `Name(Arg);` calling the OpenMP lock routine
+/// \p Name, return Arg.
+static const Expr *getLockCallArg(const Stmt *S, StringRef Name) {
+ const CallExpr *CE = getLockCall(S, Name);
+ return CE ? CE->getArg(0)->IgnoreParenImpCasts() : nullptr;
+}
+
+/// Checks that control can enter \p S only at its start and leave it only at
+/// its end, and that \p S contains no OpenMP directive and makes no use of an
+/// OpenMP lock routine. Returns why not, if it does not. \p InLoop and
+/// \p InSwitch say whether an enclosing loop or switch statement is itself part
+/// of the sequence being checked.
+static std::optional<OMPLockSequenceRejection>
+checkSerializable(const Stmt *S, bool InLoop, bool InSwitch) {
+ using R = OMPLockSequenceRejection;
+ if (!S)
+ return std::nullopt;
+ if (isa<OMPExecutableDirective>(S))
+ return R::Directive;
+ if (isa<ReturnStmt, GotoStmt, IndirectGotoStmt, LabelStmt, CoreturnStmt,
+ CoroutineSuspendExpr, CXXTryStmt, SEHTryStmt, SEHLeaveStmt,
+ ObjCAtTryStmt, ObjCAtThrowStmt>(S))
+ return R::Escape;
+ if (const auto *Asm = dyn_cast<GCCAsmStmt>(S); Asm && Asm->isAsmGoto())
+ return R::Escape;
+ // A lock taken or released conditionally, or other than in a pair at the top
+ // level of the sequence, could be held from one thread's turn to the next.
+ if (const auto *DRE = dyn_cast<DeclRefExpr>(S);
+ DRE && isOMPLockRoutine(DRE->getDecl()))
+ return R::OtherLockUse;
+ if (isa<BreakStmt>(S))
+ return InLoop || InSwitch ? std::nullopt : std::optional(R::Escape);
+ if (isa<ContinueStmt>(S))
+ return InLoop ? std::nullopt : std::optional(R::Escape);
+ if (isa<SwitchCase>(S) && !InSwitch)
+ return R::Escape;
+ // The bodies of lambdas and blocks belong to other functions.
+ if (isa<LambdaExpr, BlockExpr>(S))
+ return std::nullopt;
+ bool IsLoop = isa<ForStmt, WhileStmt, DoStmt, CXXForRangeStmt>(S);
+ bool IsSwitch = isa<SwitchStmt>(S);
+ for (const Stmt *Child : S->children())
+ if (auto Why =
+ checkSerializable(Child, InLoop || IsLoop, InSwitch || IsSwitch))
+ return Why;
+ return std::nullopt;
+}
+
+OMPLockSequence clang::matchOMPLockSequence(ArrayRef<Stmt *> Stmts,
+ const ASTContext &Ctx) {
+ using R = OMPLockSequenceRejection;
+ OMPLockSequence Result;
+ if (Stmts.empty())
+ return Result;
+
+ // Code generation cannot put a label inside the loop that runs the threads
+ // through the sequence one at a time, since control would enter the loop
+ // through it.
+ const Stmt *First = Stmts.front();
+ if (isa<LabelStmt, SwitchCase>(First)) {
+ const Stmt *Sub = First;
+ while (const auto *L = dyn_cast<LabelStmt>(Sub))
+ Sub = L->getSubStmt();
+ while (const auto *C = dyn_cast<SwitchCase>(Sub))
+ Sub = C->getSubStmt();
+ if ((Result.SetCall = getLockCall(Sub, "omp_set_lock")))
+ Result.Rejection = R::Labelled;
+ return Result;
+ }
+
+ Result.SetCall = getLockCall(First, "omp_set_lock");
+ if (!Result.SetCall)
+ return Result;
+ auto GetLockID =
+ [&](const Expr *Lock) -> std::optional<llvm::FoldingSetNodeID> {
+ if (Lock->HasSideEffects(Ctx))
+ return std::nullopt;
+ llvm::FoldingSetNodeID ID;
+ Lock->Profile(ID, Ctx, /*Canonical=*/true);
+ return ID;
+ };
+ auto Reject = [&](R Why) {
+ Result.Rejection = Why;
+ return Result;
+ };
+
+ // The locks set in the sequence and not yet unset, innermost last.
+ SmallVector<llvm::FoldingSetNodeID, 2> Held;
+ auto ID = GetLockID(Result.SetCall->getArg(0)->IgnoreParenImpCasts());
+ if (!ID)
+ return Reject(R::SideEffects);
+ Held.push_back(*ID);
+ for (unsigned I = 1, E = Stmts.size(); I != E; ++I) {
+ const Stmt *S = Stmts[I];
+ if (const Expr *Set = getLockCallArg(S, "omp_set_lock")) {
+ auto ID = GetLockID(Set);
+ if (!ID)
+ return Reject(R::SideEffects);
+ if (llvm::is_contained(Held, *ID))
+ return Reject(R::OtherLockUse);
+ Held.push_back(*ID);
+ continue;
+ }
+ if (const Expr *Unset = getLockCallArg(S, "omp_unset_lock")) {
+ auto ID = GetLockID(Unset);
+ if (!ID)
+ return Reject(R::SideEffects);
+ if (*ID != Held.back())
+ return Reject(R::OtherLockUse);
+ Held.pop_back();
+ if (Held.empty()) {
+ Result.Length = I + 1;
+ return Result;
+ }
+ continue;
+ }
+ // A declaration would remain in scope after the sequence ends.
+ if (isa<DeclStmt>(S))
+ return Reject(R::Declaration);
+ if (auto Why = checkSerializable(S, /*InLoop=*/false, /*InSwitch=*/false))
+ return Reject(*Why);
+ }
+ return Reject(R::NoUnset);
+}
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.h b/clang/lib/CodeGen/CGOpenMPRuntime.h
index 47c05d62a3b41..3189130ca343b 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -804,6 +804,16 @@ class CGOpenMPRuntime {
OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
const Expr *Message = nullptr);
+ /// Called while emitting the statements of a compound statement in device
+ /// code, with \p Stmts the statements not yet emitted. If a sequence of them
+ /// starting with the first needs to be emitted as a whole, emits it and
+ /// returns the number of statements emitted; otherwise returns 0 and emits
+ /// nothing.
+ virtual unsigned emitStmtSequence(CodeGenFunction &CGF,
+ ArrayRef<Stmt *> Stmts) {
+ return 0;
+ }
+
/// Emits a critical region.
/// \param CriticalName Name of the critical region.
/// \param CriticalOpGen Generator for the statement associated with the given
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 2d4e8577b88b8..6f17eff44924c 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -18,6 +18,7 @@
#include "clang/AST/Attr.h"
#include "clang/AST/DeclOpenMP.h"
#include "clang/AST/OpenMPClause.h"
+#include "clang/AST/OpenMPLockSequence.h"
#include "clang/AST/StmtOpenMP.h"
#include "clang/AST/StmtVisitor.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -1389,6 +1390,20 @@ void CGOpenMPRuntimeGPU::emitLaneSerializedRegion(
CGF.Builder.restoreIP(AfterIP);
}
+unsigned CGOpenMPRuntimeGPU::emitStmtSequence(CodeGenFunction &CGF,
+ ArrayRef<Stmt *> Stmts) {
+ if (!CGM.getTarget().getGridValue().GV_Lockstep_Lanes)
+ return 0;
+ OMPLockSequence Seq = matchOMPLockSequence(Stmts, CGM.getContext());
+ if (!Seq.Length)
+ return 0;
+ emitLaneSerializedRegion(CGF, [&] {
+ for (const Stmt *S : Stmts.take_front(Seq.Length))
+ CGF.EmitStmt(S);
+ });
+ return Seq.Length;
+}
+
void CGOpenMPRuntimeGPU::emitCriticalRegion(
CodeGenFunction &CGF, StringRef Cri...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/242480
More information about the llvm-branch-commits
mailing list