Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
099c502
[OpenMP] Add parser/semantic support for dyn_groupprivate clause
kevinsala Aug 8, 2025
fa3c742
[OpenMP][Offload] Add offload runtime support for dyn_groupprivate cl…
kevinsala Aug 8, 2025
f66e5fa
[OpenMP] Add codegen support for dyn_groupprivate clause
kevinsala Aug 8, 2025
f20f4ba
Add fixes
kevinsala Aug 10, 2025
c34e062
[OpenMP][Flang] Add empty clause support for dyn_groupprivate in Flang
kevinsala Aug 17, 2025
96a73ab
Merge branch 'main' into users/kevinsala/omp-dyn-groupprivate-pr
kparzysz Aug 18, 2025
0a7a96d
Fix merge in ClauseT.h
kparzysz Aug 18, 2025
b5b8439
more merge fixes
kparzysz Aug 18, 2025
6e4c547
more merge fixes
kparzysz Aug 18, 2025
776401c
Merge remote-tracking branch 'upstream/main' into users/kevinsala/omp…
kevinsala Aug 22, 2025
84fc963
Add fixes and improvements after merge
kevinsala Aug 25, 2025
00550f9
Merge remote-tracking branch 'upstream/users/kevinsala/omp-dyn-groupp…
kevinsala Aug 25, 2025
c698b84
Merge remote-tracking branch 'upstream/users/kevinsala/omp-dyn-groupp…
kevinsala Aug 25, 2025
86f0cf0
Update syntax for fallback complex modifier
kevinsala Oct 23, 2025
86d4e6d
Merge remote-tracking branch 'upstream/main' into users/kevinsala/omp…
kevinsala Oct 24, 2025
f9eee16
Merge branch 'users/kevinsala/omp-dyn-groupprivate-pr' into users/kev…
kevinsala Oct 24, 2025
3a2fe70
Update for fallback complex modifier
kevinsala Oct 25, 2025
d4bf656
Merge branch 'users/kevinsala/omp-dyn-groupprivate-codegen-pr' into u…
kevinsala Oct 26, 2025
5f68ea0
Add support for null fallback
kevinsala Oct 26, 2025
9fb6e27
Fix test
kevinsala Oct 27, 2025
4662a4f
Fix parsing
kevinsala Oct 27, 2025
64e7abc
Fix format
kevinsala Oct 27, 2025
3307ec1
Merge branch 'users/kevinsala/omp-dyn-groupprivate-pr' into users/kev…
kevinsala Oct 27, 2025
968cc69
Merge branch 'users/kevinsala/omp-dyn-groupprivate-codegen-pr' into u…
kevinsala Oct 27, 2025
7b53c9a
Fix review comments
kevinsala Oct 27, 2025
79b34f1
Fix more review comments
kevinsala Oct 27, 2025
c4905e0
Fix initialization of a fallback variable
kevinsala Oct 30, 2025
b1930db
Merge branch 'users/kevinsala/omp-dyn-groupprivate-codegen-pr' into u…
kevinsala Oct 30, 2025
c439e44
Add codegen test for dyn_groupprivate
kevinsala Oct 30, 2025
407e41f
Merge branch 'users/kevinsala/omp-dyn-groupprivate-codegen-pr' into u…
kevinsala Oct 30, 2025
b76e32c
Fix review comments
kevinsala Nov 2, 2025
03db991
Merge branch 'users/kevinsala/omp-dyn-groupprivate-pr' into users/kev…
kevinsala Nov 2, 2025
944b7e7
Merge branch 'users/kevinsala/omp-dyn-groupprivate-codegen-pr' into u…
kevinsala Nov 2, 2025
a3cd7ef
Add cgroup mem parameters in createTarget
kevinsala Nov 4, 2025
0fa3d30
Merge remote-tracking branch 'upstream/main' into users/kevinsala/omp…
kevinsala Nov 7, 2025
a59d104
Merge branch 'users/kevinsala/omp-dyn-groupprivate-codegen-pr' into u…
kevinsala Nov 7, 2025
42eaac1
Fix format
kevinsala Nov 8, 2025
81f2225
Merge remote-tracking branch 'upstream/main' into users/kevinsala/omp…
kevinsala Nov 9, 2025
0ead633
Merge branch 'users/kevinsala/omp-dyn-groupprivate-codegen-pr' into u…
kevinsala Nov 9, 2025
0062013
Merge remote-tracking branch 'upstream/main' into users/kevinsala/omp…
kevinsala Nov 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -9768,6 +9768,161 @@ class OMPXDynCGroupMemClause
Expr *getSize() const { return getStmtAs<Expr>(); }
};

/// This represents 'dyn_groupprivate' clause in '#pragma omp target ...'
/// and '#pragma omp teams ...' directives.
///
/// \code
/// #pragma omp target [...] dyn_groupprivate(a,b: N)
/// \endcode
class OMPDynGroupprivateClause : public OMPClause, public OMPClauseWithPreInit {
friend class OMPClauseReader;

/// Location of '('.
SourceLocation LParenLoc;

/// Modifiers for 'dyn_groupprivate' clause.
enum { FIRST, SECOND, NUM_MODIFIERS };
OpenMPDynGroupprivateClauseModifier Modifiers[NUM_MODIFIERS];

/// Locations of modifiers.
SourceLocation ModifiersLoc[NUM_MODIFIERS];

/// The size of the dyn_groupprivate.
Expr *Size = nullptr;

/// Set the first dyn_groupprivate modifier.
///
/// \param M The modifier.
void setFirstDynGroupprivateModifier(OpenMPDynGroupprivateClauseModifier M) {
Modifiers[FIRST] = M;
}

/// Set the second dyn_groupprivate modifier.
///
/// \param M The modifier.
void setSecondDynGroupprivateModifier(OpenMPDynGroupprivateClauseModifier M) {
Modifiers[SECOND] = M;
}

/// Set location of the first dyn_groupprivate modifier.
void setFirstDynGroupprivateModifierLoc(SourceLocation Loc) {
ModifiersLoc[FIRST] = Loc;
}

/// Set location of the second dyn_groupprivate modifier.
void setSecondDynGroupprivateModifierLoc(SourceLocation Loc) {
ModifiersLoc[SECOND] = Loc;
}

/// Set dyn_groupprivate modifier location.
///
/// \param M The modifier location.
void setDynGroupprivateModifer(OpenMPDynGroupprivateClauseModifier M) {
if (Modifiers[FIRST] == OMPC_DYN_GROUPPRIVATE_unknown)
Modifiers[FIRST] = M;
else {
assert(Modifiers[SECOND] == OMPC_DYN_GROUPPRIVATE_unknown);
Modifiers[SECOND] = M;
}
}

/// Sets the location of '('.
///
/// \param Loc Location of '('.
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }

/// Set size.
///
/// \param E Size.
void setSize(Expr *E) { Size = E; }

public:
/// Build 'dyn_groupprivate' clause with a size expression \a Size.
///
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
/// \param Size Size.
/// \param M1 The first modifier applied to 'dyn_groupprivate' clause.
/// \param M1Loc Location of the first modifier.
/// \param M2 The second modifier applied to 'dyn_groupprivate' clause.
/// \param M2Loc Location of the second modifier.
OMPDynGroupprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc, Expr *Size, Stmt *HelperSize,
OpenMPDirectiveKind CaptureRegion,
OpenMPDynGroupprivateClauseModifier M1,
SourceLocation M1Loc,
OpenMPDynGroupprivateClauseModifier M2,
SourceLocation M2Loc)
: OMPClause(llvm::omp::OMPC_dyn_groupprivate, StartLoc, EndLoc),
OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Size(Size) {
setPreInitStmt(HelperSize, CaptureRegion);
Modifiers[FIRST] = M1;
Modifiers[SECOND] = M2;
ModifiersLoc[FIRST] = M1Loc;
ModifiersLoc[SECOND] = M2Loc;
}

/// Build an empty clause.
explicit OMPDynGroupprivateClause()
: OMPClause(llvm::omp::OMPC_dyn_groupprivate, SourceLocation(),
SourceLocation()),
OMPClauseWithPreInit(this) {
Modifiers[FIRST] = OMPC_DYN_GROUPPRIVATE_unknown;
Modifiers[SECOND] = OMPC_DYN_GROUPPRIVATE_unknown;
}

/// Get the first modifier of the clause.
OpenMPDynGroupprivateClauseModifier getFirstDynGroupprivateModifier() const {
return Modifiers[FIRST];
}

/// Get the second modifier of the clause.
OpenMPDynGroupprivateClauseModifier getSecondDynGroupprivateModifier() const {
return Modifiers[SECOND];
}

/// Get location of '('.
SourceLocation getLParenLoc() { return LParenLoc; }

/// Get the first modifier location.
SourceLocation getFirstDynGroupprivateModifierLoc() const {
return ModifiersLoc[FIRST];
}

/// Get the second modifier location.
SourceLocation getSecondDynGroupprivateModifierLoc() const {
return ModifiersLoc[SECOND];
}

/// Get size.
Expr *getSize() { return Size; }

/// Get size.
const Expr *getSize() const { return Size; }

child_range children() {
return child_range(reinterpret_cast<Stmt **>(&Size),
reinterpret_cast<Stmt **>(&Size) + 1);
}

const_child_range children() const {
auto Children = const_cast<OMPDynGroupprivateClause *>(this)->children();
return const_child_range(Children.begin(), Children.end());
}

child_range used_children() {
return child_range(child_iterator(), child_iterator());
}
const_child_range used_children() const {
return const_child_range(const_child_iterator(), const_child_iterator());
}

static bool classof(const OMPClause *T) {
return T->getClauseKind() == llvm::omp::OMPC_dyn_groupprivate;
}
};

/// This represents the 'doacross' clause for the '#pragma omp ordered'
/// directive.
///
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4060,6 +4060,14 @@ bool RecursiveASTVisitor<Derived>::VisitOMPXDynCGroupMemClause(
return true;
}

template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPDynGroupprivateClause(
OMPDynGroupprivateClause *C) {
TRY_TO(VisitOMPClauseWithPreInit(C));
TRY_TO(TraverseStmt(C->getSize()));
return true;
}

template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPDoacrossClause(
OMPDoacrossClause *C) {
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11995,6 +11995,9 @@ def err_omp_unexpected_schedule_modifier : Error<
"modifier '%0' cannot be used along with modifier '%1'">;
def err_omp_schedule_nonmonotonic_static : Error<
"'nonmonotonic' modifier can only be specified with 'dynamic' or 'guided' schedule kind">;
def err_omp_unexpected_dyn_groupprivate_modifier
: Error<"modifier '%0' cannot be used along with modifier '%1' in "
"dyn_groupprivate">;
def err_omp_simple_clause_incompatible_with_ordered : Error<
"'%0' clause with '%1' modifier cannot be specified if an 'ordered' clause is specified">;
def err_omp_ordered_simd : Error<
Expand Down
9 changes: 9 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
#ifndef OPENMP_GRAINSIZE_MODIFIER
#define OPENMP_GRAINSIZE_MODIFIER(Name)
#endif
#ifndef OPENMP_DYN_GROUPPRIVATE_MODIFIER
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name)
#endif
#ifndef OPENMP_NUMTASKS_MODIFIER
#define OPENMP_NUMTASKS_MODIFIER(Name)
#endif
Expand Down Expand Up @@ -227,6 +230,11 @@ OPENMP_BIND_KIND(thread)
// Modifiers for the 'grainsize' clause.
OPENMP_GRAINSIZE_MODIFIER(strict)

// Modifiers for the 'dyn_groupprivate' clause.
OPENMP_DYN_GROUPPRIVATE_MODIFIER(cgroup)
OPENMP_DYN_GROUPPRIVATE_MODIFIER(strict)
OPENMP_DYN_GROUPPRIVATE_MODIFIER(fallback)

// Modifiers for the 'num_tasks' clause.
OPENMP_NUMTASKS_MODIFIER(strict)

Expand All @@ -245,6 +253,7 @@ OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)

#undef OPENMP_NUMTASKS_MODIFIER
#undef OPENMP_NUMTHREADS_MODIFIER
#undef OPENMP_DYN_GROUPPRIVATE_MODIFIER
#undef OPENMP_GRAINSIZE_MODIFIER
#undef OPENMP_BIND_KIND
#undef OPENMP_ADJUST_ARGS_KIND
Expand Down
10 changes: 10 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ enum OpenMPGrainsizeClauseModifier {
OMPC_GRAINSIZE_unknown
};

enum OpenMPDynGroupprivateClauseModifier {
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) OMPC_DYN_GROUPPRIVATE_##Name,
#include "clang/Basic/OpenMPKinds.def"
OMPC_DYN_GROUPPRIVATE_unknown
};

/// Number of allowed dyn_groupprivate-modifiers.
static constexpr unsigned NumberOfOMPDynGroupprivateClauseModifiers =
OMPC_DYN_GROUPPRIVATE_unknown;

enum OpenMPNumTasksClauseModifier {
#define OPENMP_NUMTASKS_MODIFIER(Name) OMPC_NUMTASKS_##Name,
#include "clang/Basic/OpenMPKinds.def"
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Sema/SemaOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,13 @@ class SemaOpenMP : public SemaBase {
SourceLocation LParenLoc,
SourceLocation EndLoc);

/// Called on a well-formed 'dyn_groupprivate' clause.
OMPClause *ActOnOpenMPDynGroupprivateClause(
OpenMPDynGroupprivateClauseModifier M1,
OpenMPDynGroupprivateClauseModifier M2, Expr *Size,
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc,
SourceLocation M2Loc, SourceLocation EndLoc);

/// Called on well-formed 'doacross' clause.
OMPClause *
ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType,
Expand Down
21 changes: 21 additions & 0 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
return static_cast<const OMPFilterClause *>(C);
case OMPC_ompx_dyn_cgroup_mem:
return static_cast<const OMPXDynCGroupMemClause *>(C);
case OMPC_dyn_groupprivate:
return static_cast<const OMPDynGroupprivateClause *>(C);
case OMPC_default:
case OMPC_proc_bind:
case OMPC_safelen:
Expand Down Expand Up @@ -2725,6 +2727,25 @@ void OMPClausePrinter::VisitOMPXDynCGroupMemClause(
OS << ")";
}

void OMPClausePrinter::VisitOMPDynGroupprivateClause(
OMPDynGroupprivateClause *Node) {
OS << "dyn_groupprivate(";
if (Node->getFirstDynGroupprivateModifier() !=
OMPC_DYN_GROUPPRIVATE_unknown) {
OS << getOpenMPSimpleClauseTypeName(
OMPC_dyn_groupprivate, Node->getFirstDynGroupprivateModifier());
if (Node->getSecondDynGroupprivateModifier() !=
OMPC_DYN_GROUPPRIVATE_unknown) {
OS << ", ";
OS << getOpenMPSimpleClauseTypeName(
OMPC_dyn_groupprivate, Node->getSecondDynGroupprivateModifier());
}
OS << ": ";
}
Node->getSize()->printPretty(OS, nullptr, Policy, 0);
OS << ')';
}

void OMPClausePrinter::VisitOMPDoacrossClause(OMPDoacrossClause *Node) {
OS << "doacross(";
OpenMPDoacrossClauseModifier DepType = Node->getDependenceType();
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/AST/StmtProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,12 @@ void OMPClauseProfiler::VisitOMPXDynCGroupMemClause(
if (Expr *Size = C->getSize())
Profiler->VisitStmt(Size);
}
void OMPClauseProfiler::VisitOMPDynGroupprivateClause(
const OMPDynGroupprivateClause *C) {
VistOMPClauseWithPreInit(C);
if (auto *Size = C->getSize())
Profiler->VisitStmt(Size);
}
void OMPClauseProfiler::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {
VisitOMPClauseList(C);
}
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/Basic/OpenMPKinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
return OMPC_GRAINSIZE_unknown;
return Type;
}
case OMPC_dyn_groupprivate: {
return llvm::StringSwitch<unsigned>(Str)
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) \
.Case(#Name, OMPC_DYN_GROUPPRIVATE_##Name)
#include "clang/Basic/OpenMPKinds.def"
.Default(OMPC_DYN_GROUPPRIVATE_unknown);
}
case OMPC_num_tasks: {
unsigned Type = llvm::StringSwitch<unsigned>(Str)
#define OPENMP_NUMTASKS_MODIFIER(Name) .Case(#Name, OMPC_NUMTASKS_##Name)
Expand Down Expand Up @@ -508,6 +515,16 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'grainsize' clause modifier");
case OMPC_dyn_groupprivate:
switch (Type) {
case OMPC_DYN_GROUPPRIVATE_unknown:
return "unknown";
#define OPENMP_DYN_GROUPPRIVATE_MODIFIER(Name) \
case OMPC_DYN_GROUPPRIVATE_##Name: \
return #Name;
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'dyn_groupprivate' clause modifier");
case OMPC_num_tasks:
switch (Type) {
case OMPC_NUMTASKS_unknown:
Expand Down
40 changes: 26 additions & 14 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9489,18 +9489,30 @@ static llvm::Value *emitDeviceID(
return DeviceID;
}

static llvm::Value *emitDynCGGroupMem(const OMPExecutableDirective &D,
CodeGenFunction &CGF) {
llvm::Value *DynCGroupMem = CGF.Builder.getInt32(0);

if (auto *DynMemClause = D.getSingleClause<OMPXDynCGroupMemClause>()) {
CodeGenFunction::RunCleanupsScope DynCGroupMemScope(CGF);
llvm::Value *DynCGroupMemVal = CGF.EmitScalarExpr(
DynMemClause->getSize(), /*IgnoreResultAssign=*/true);
DynCGroupMem = CGF.Builder.CreateIntCast(DynCGroupMemVal, CGF.Int32Ty,
/*isSigned=*/false);
}
return DynCGroupMem;
static std::pair<llvm::Value *, bool>
emitDynCGroupMem(const OMPExecutableDirective &D, CodeGenFunction &CGF) {
llvm::Value *DynGP = CGF.Builder.getInt32(0);
bool DynGPFallback = false;

if (auto *DynGPClause = D.getSingleClause<OMPDynGroupprivateClause>()) {
CodeGenFunction::RunCleanupsScope DynGPScope(CGF);
llvm::Value *DynGPVal =
CGF.EmitScalarExpr(DynGPClause->getSize(), /*IgnoreResultAssign=*/true);
DynGP = CGF.Builder.CreateIntCast(DynGPVal, CGF.Int32Ty,
/*isSigned=*/false);
DynGPFallback = (DynGPClause->getFirstDynGroupprivateModifier() !=
OMPC_DYN_GROUPPRIVATE_strict &&
DynGPClause->getSecondDynGroupprivateModifier() !=
OMPC_DYN_GROUPPRIVATE_strict);
} else if (auto *OMPXDynCGClause =
D.getSingleClause<OMPXDynCGroupMemClause>()) {
CodeGenFunction::RunCleanupsScope DynCGMemScope(CGF);
llvm::Value *DynCGMemVal = CGF.EmitScalarExpr(OMPXDynCGClause->getSize(),
/*IgnoreResultAssign=*/true);
DynGP = CGF.Builder.CreateIntCast(DynCGMemVal, CGF.Int32Ty,
/*isSigned=*/false);
}
return {DynGP, DynGPFallback};
}
static void genMapInfoForCaptures(
MappableExprsHandler &MEHandler, CodeGenFunction &CGF,
Expand Down Expand Up @@ -9710,7 +9722,7 @@ static void emitTargetCallKernelLaunch(
llvm::Value *RTLoc = OMPRuntime->emitUpdateLocation(CGF, D.getBeginLoc());
llvm::Value *NumIterations =
OMPRuntime->emitTargetNumIterationsCall(CGF, D, SizeEmitter);
llvm::Value *DynCGGroupMem = emitDynCGGroupMem(D, CGF);
auto [DynCGroupMem, DynCGroupMemFallback] = emitDynCGroupMem(D, CGF);
llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
CGF.AllocaInsertPt->getParent(), CGF.AllocaInsertPt->getIterator());

Expand All @@ -9720,7 +9732,7 @@ static void emitTargetCallKernelLaunch(

llvm::OpenMPIRBuilder::TargetKernelArgs Args(
NumTargetItems, RTArgs, NumIterations, NumTeams, NumThreads,
DynCGGroupMem, HasNoWait);
DynCGroupMem, HasNoWait, DynCGroupMemFallback);

llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
cantFail(OMPRuntime->getOMPBuilder().emitKernelLaunch(
Expand Down
Loading
Loading