Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
924b89f
[OpenMP] Parsing Support of ThreadSets in Task
Ritanya-B-Bharadwaj Apr 6, 2025
1571311
[clang][OpenMP] New OpenMP 6.0 threadset clause
Ritanya-B-Bharadwaj Apr 15, 2025
14d1984
[clang] [OpenMP] Codegen support for threadset
Ritanya-B-Bharadwaj Apr 20, 2025
88f75e7
Adding basic runtime support
Ritanya-B-Bharadwaj May 22, 2025
48522e4
Removing runtime changes
Ritanya-B-Bharadwaj Jun 16, 2025
a9401e6
Update clang/lib/CodeGen/CGOpenMPRuntime.cpp
Ritanya-B-Bharadwaj Jul 8, 2025
b64cf92
Update clang/include/clang/AST/OpenMPClause.h
Ritanya-B-Bharadwaj Jul 24, 2025
68b691b
Resolving flang build failure
Ritanya-B-Bharadwaj Jul 26, 2025
04e706d
Merge branch 'main' into ThreadSet
Ritanya-B-Bharadwaj Sep 1, 2025
812fe2b
Merge branch 'main' into ThreadSet
Ritanya-B-Bharadwaj Sep 1, 2025
149f264
Fixing formatting issues
Ritanya-B-Bharadwaj Sep 1, 2025
6ecfbc0
Fixing formatting issues
Ritanya-B-Bharadwaj Sep 1, 2025
8694708
Merge branch 'main' into ThreadSet
Ritanya-B-Bharadwaj Sep 1, 2025
fdb4841
Update OpenMPKinds.cpp
Ritanya-B-Bharadwaj Sep 1, 2025
ea0e55f
Update OMP.td
Ritanya-B-Bharadwaj Sep 1, 2025
2602c6c
Restore original version of OpenMPSupport.rst
Ritanya-B-Bharadwaj Sep 1, 2025
18e880a
Merge branch 'main' into ThreadSet
Ritanya-B-Bharadwaj Oct 7, 2025
b0b3fdb
Merge branch 'main' into ThreadSet
Ritanya-B-Bharadwaj Oct 7, 2025
451633e
Fixing merge conflicts on OpenMPSupport.rst
Ritanya-B-Bharadwaj Oct 7, 2025
6404c00
flang changes
Ritanya-B-Bharadwaj Oct 8, 2025
42f62c6
Merge branch 'main' into ThreadSet
Ritanya-B-Bharadwaj Oct 9, 2025
cbf4671
Updating OpenMPSupport.rst format
Ritanya-B-Bharadwaj Oct 15, 2025
a5dc8d2
Merge branch 'main' into ThreadSet
Ritanya-B-Bharadwaj Oct 15, 2025
9e74f9b
Update OpenMPSupport.rst
Ritanya-B-Bharadwaj Oct 15, 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
1,024 changes: 512 additions & 512 deletions clang/docs/OpenMPSupport.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ OpenMP Support
modifier in the ``adjust_args`` clause.
- Allow array length to be omitted in array section subscript expression.
- Fixed non-contiguous strided update in the ``omp target update`` directive with the ``from`` clause.
- Added support for threadset clause in task and taskloop directives.

Improvements
^^^^^^^^^^^^
Expand Down
80 changes: 80 additions & 0 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,86 @@ class OMPDefaultClause : public OMPClause {
}
};

/// This represents 'threadset' clause in the '#pragma omp task ...' directive.
///
/// \code
/// #pragma omp task threadset(omp_pool)
/// \endcode
/// In this example directive '#pragma omp task' has simple 'threadset'
/// clause with kind 'omp_pool'.
class OMPThreadsetClause final : public OMPClause {
friend class OMPClauseReader;

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

/// A kind of the 'threadset' clause.
OpenMPThreadsetKind Kind = OMPC_THREADSET_unknown;

/// Start location of the kind in source code.
SourceLocation KindLoc;

/// Set kind of the clauses.
///
/// \param K Argument of clause.
void setThreadsetKind(OpenMPThreadsetKind K) { Kind = K; }

/// Set argument location.
///
/// \param KLoc Argument location.
void setThreadsetKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }

public:
/// Build 'threadset' clause with argument \a A ('omp_team' or 'omp_pool').
///
/// \param A Argument of the clause ('omp_team' or 'omp_pool').
/// \param ALoc Starting location of the argument.
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
OMPThreadsetClause(OpenMPThreadsetKind A, SourceLocation ALoc,
SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc)
: OMPClause(llvm::omp::OMPC_threadset, StartLoc, EndLoc),
LParenLoc(LParenLoc), Kind(A), KindLoc(ALoc) {}

/// Build an empty clause.
OMPThreadsetClause()
: OMPClause(llvm::omp::OMPC_threadset, SourceLocation(),
SourceLocation()) {}

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

/// Returns the location of '('.
SourceLocation getLParenLoc() const { return LParenLoc; }

/// Returns kind of the clause.
OpenMPThreadsetKind getThreadsetKind() const { return Kind; }

/// Returns location of clause kind.
SourceLocation getThreadsetKindLoc() const { return KindLoc; }

child_range children() {
return child_range(child_iterator(), child_iterator());
}

const_child_range children() const {
return const_child_range(const_child_iterator(), const_child_iterator());
}

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_threadset;
}
};

/// This represents 'proc_bind' clause in the '#pragma omp ...'
/// directive.
///
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,12 @@ bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
return true;
}

template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPThreadsetClause(
OMPThreadsetClause *) {
return true;
}

template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
return true;
Expand Down
8 changes: 7 additions & 1 deletion clang/include/clang/Basic/OpenMPKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
#ifndef OPENMP_ALLOCATE_MODIFIER
#define OPENMP_ALLOCATE_MODIFIER(Name)
#endif
#ifndef OPENMP_THREADSET_KIND
#define OPENMP_THREADSET_KIND(Name)
#endif

// Static attributes for 'schedule' clause.
OPENMP_SCHEDULE_KIND(static)
Expand Down Expand Up @@ -243,6 +246,9 @@ OPENMP_DOACROSS_MODIFIER(sink)
OPENMP_DOACROSS_MODIFIER(sink_omp_cur_iteration)
OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)

OPENMP_THREADSET_KIND(omp_pool)
OPENMP_THREADSET_KIND(omp_team)

#undef OPENMP_NUMTASKS_MODIFIER
#undef OPENMP_NUMTHREADS_MODIFIER
#undef OPENMP_GRAINSIZE_MODIFIER
Expand Down Expand Up @@ -271,4 +277,4 @@ OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)
#undef OPENMP_DEFAULTMAP_MODIFIER
#undef OPENMP_DOACROSS_MODIFIER
#undef OPENMP_ALLOCATE_MODIFIER

#undef OPENMP_THREADSET_KIND
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ enum OpenMPAllocateClauseModifier {
OMPC_ALLOCATE_unknown
};

/// OpenMP modifiers for 'threadset' clause.
enum OpenMPThreadsetKind {
#define OPENMP_THREADSET_KIND(Name) OMPC_THREADSET_##Name,
#include "clang/Basic/OpenMPKinds.def"
OMPC_THREADSET_unknown
};

/// Number of allowed allocate-modifiers.
static constexpr unsigned NumberOfOMPAllocateClauseModifiers =
OMPC_ALLOCATE_unknown;
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Sema/SemaOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,12 @@ class SemaOpenMP : public SemaBase {
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
/// Called on well-formed 'threadset' clause.
OMPClause *ActOnOpenMPThreadsetClause(OpenMPThreadsetKind Kind,
SourceLocation KindLoc,
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
/// Called on well-formed 'proc_bind' clause.
OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind,
SourceLocation KindLoc,
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
case OMPC_nowait:
case OMPC_untied:
case OMPC_mergeable:
case OMPC_threadset:
case OMPC_threadprivate:
case OMPC_flush:
case OMPC_depobj:
Expand Down Expand Up @@ -1914,6 +1915,13 @@ void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
<< ")";
}

void OMPClausePrinter::VisitOMPThreadsetClause(OMPThreadsetClause *Node) {
OS << "threadset("
<< getOpenMPSimpleClauseTypeName(OMPC_threadset,
unsigned(Node->getThreadsetKind()))
<< ")";
}

void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
OS << "proc_bind("
<< getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/AST/StmtProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ void OMPClauseProfiler::VisitOMPNocontextClause(const OMPNocontextClause *C) {

void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }

void OMPClauseProfiler::VisitOMPThreadsetClause(const OMPThreadsetClause *C) {}

void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }

void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
Expand Down
19 changes: 19 additions & 0 deletions clang/lib/Basic/OpenMPKinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
#define OPENMP_ALLOCATE_MODIFIER(Name) .Case(#Name, OMPC_ALLOCATE_##Name)
#include "clang/Basic/OpenMPKinds.def"
.Default(OMPC_ALLOCATE_unknown);
case OMPC_threadset: {
unsigned Type = llvm::StringSwitch<unsigned>(Str)
#define OPENMP_THREADSET_KIND(Name) .Case(#Name, OMPC_THREADSET_##Name)
#include "clang/Basic/OpenMPKinds.def"
.Default(OMPC_THREADSET_unknown);
if (LangOpts.OpenMP < 60)
return OMPC_THREADSET_unknown;
return Type;
}
case OMPC_num_threads: {
unsigned Type = llvm::StringSwitch<unsigned>(Str)
#define OPENMP_NUMTHREADS_MODIFIER(Name) .Case(#Name, OMPC_NUMTHREADS_##Name)
Expand Down Expand Up @@ -538,6 +547,16 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'num_threads' clause modifier");
case OMPC_threadset:
switch (Type) {
case OMPC_THREADSET_unknown:
return "unknown";
#define OPENMP_THREADSET_KIND(Name) \
case OMPC_THREADSET_##Name: \
return #Name;
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'threadset' clause modifier");
case OMPC_unknown:
case OMPC_threadprivate:
case OMPC_if:
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3700,6 +3700,7 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
DestructorsFlag = 0x8,
PriorityFlag = 0x20,
DetachableFlag = 0x40,
FreeAgentFlag = 0x80,
Copy link
Member

@alexey-bataev alexey-bataev Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this flag implemented in runtime already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};
unsigned Flags = Data.Tied ? TiedFlag : 0;
bool NeedsCleanup = false;
Expand All @@ -3709,6 +3710,11 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
if (NeedsCleanup)
Flags = Flags | DestructorsFlag;
}
if (const auto *Clause = D.getSingleClause<OMPThreadsetClause>()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to pass the flag as part of the Data parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but could you clarify why that would be necessary? All the flags above seem to be combined using the | operator, so this appears consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep all the flags and processing in one single place

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I’m not sure I fully understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this flag, I followed the existing pattern where flags are handled directly, not through the data parameter, to stay consistent. Since the other flags are also managed this way, it didn’t seem necessary to change it just for this case. However, if you think using the data parameter is the right approach, I can take it up separately as a new task — to modify the existing features and add support for passing all flags via the data parameter.

OpenMPThreadsetKind Kind = Clause->getThreadsetKind();
if (Kind == OMPC_THREADSET_omp_pool)
Flags = Flags | FreeAgentFlag;
}
if (Data.Priority.getInt())
Flags = Flags | PriorityFlag;
if (D.hasClausesOfKind<OMPDetachClause>())
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3082,6 +3082,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
else
Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective);
break;
case OMPC_threadset:
case OMPC_fail:
case OMPC_default:
case OMPC_proc_bind:
Expand Down
21 changes: 21 additions & 0 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16267,6 +16267,10 @@ OMPClause *SemaOpenMP::ActOnOpenMPSimpleClause(
static_cast<OpenMPSeverityClauseKind>(Argument), ArgumentLoc, StartLoc,
LParenLoc, EndLoc);
break;
case OMPC_threadset:
Res = ActOnOpenMPThreadsetClause(static_cast<OpenMPThreadsetKind>(Argument),
ArgumentLoc, StartLoc, LParenLoc, EndLoc);
break;
case OMPC_if:
case OMPC_final:
case OMPC_num_threads:
Expand Down Expand Up @@ -16384,6 +16388,23 @@ OMPClause *SemaOpenMP::ActOnOpenMPDefaultClause(DefaultKind Kind,
OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
}

OMPClause *SemaOpenMP::ActOnOpenMPThreadsetClause(OpenMPThreadsetKind Kind,
SourceLocation KindLoc,
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc) {
if (Kind == OMPC_THREADSET_unknown) {
Diag(KindLoc, diag::err_omp_unexpected_clause_value)
<< getListOfPossibleValues(OMPC_threadset, /*First=*/0,
/*Last=*/unsigned(OMPC_THREADSET_unknown))
<< getOpenMPClauseName(OMPC_threadset);
return nullptr;
}

return new (getASTContext())
OMPThreadsetClause(Kind, KindLoc, StartLoc, LParenLoc, EndLoc);
}

OMPClause *SemaOpenMP::ActOnOpenMPProcBindClause(ProcBindKind Kind,
SourceLocation KindKwLoc,
SourceLocation StartLoc,
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -10600,6 +10600,13 @@ TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
C->getLParenLoc(), C->getEndLoc());
}

template <typename Derived>
OMPClause *
TreeTransform<Derived>::TransformOMPThreadsetClause(OMPThreadsetClause *C) {
// No need to rebuild this clause, no template-dependent parameters.
return C;
}

template <typename Derived>
OMPClause *
TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Expand Down
14 changes: 14 additions & 0 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11256,6 +11256,9 @@ OMPClause *OMPClauseReader::readClause() {
case llvm::omp::OMPC_mergeable:
C = new (Context) OMPMergeableClause();
break;
case llvm::omp::OMPC_threadset:
C = new (Context) OMPThreadsetClause();
break;
case llvm::omp::OMPC_read:
C = new (Context) OMPReadClause();
break;
Expand Down Expand Up @@ -11648,6 +11651,17 @@ void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) {
C->setDefaultKindKwLoc(Record.readSourceLocation());
}

// Read the parameter of threadset clause. This will have been saved when
// OMPClauseWriter is called.
void OMPClauseReader::VisitOMPThreadsetClause(OMPThreadsetClause *C) {
C->setLParenLoc(Record.readSourceLocation());
SourceLocation ThreadsetKindLoc = Record.readSourceLocation();
C->setThreadsetKindLoc(ThreadsetKindLoc);
OpenMPThreadsetKind TKind =
static_cast<OpenMPThreadsetKind>(Record.readInt());
C->setThreadsetKind(TKind);
}

void OMPClauseReader::VisitOMPProcBindClause(OMPProcBindClause *C) {
C->setProcBindKind(static_cast<llvm::omp::ProcBindKind>(Record.readInt()));
C->setLParenLoc(Record.readSourceLocation());
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7886,6 +7886,12 @@ void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
Record.AddSourceLocation(C->getDefaultKindKwLoc());
}

void OMPClauseWriter::VisitOMPThreadsetClause(OMPThreadsetClause *C) {
Record.AddSourceLocation(C->getLParenLoc());
Record.AddSourceLocation(C->getThreadsetKindLoc());
Record.writeEnum(C->getThreadsetKind());
}

void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
Record.push_back(unsigned(C->getProcBindKind()));
Record.AddSourceLocation(C->getLParenLoc());
Expand Down
Loading