Skip to content
Open
2 changes: 1 addition & 1 deletion clang/docs/OpenMPSupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ implementation.
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| memscope clause for atomic and flush | :none:`unclaimed` | :none:`unclaimed` | |
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| transparent clause (hull tasks) | :none:`unclaimed` | :none:`unclaimed` | |
| transparent clause (hull tasks) | :part:`partial` | :none:`unclaimed` | https://github.com/llvm/llvm-project/pull/166810 |
+-------------------------------------------------------------+---------------------------+---------------------------+--------------------------------------------------------------------------+
| rule-based compound directives | :part:`In Progress` | :part:`In Progress` | kparzysz |
| | | | Testing for Fortran missing |
Expand Down
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ OpenMP Support
- 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.
- Added support for ``transparent`` clause in task and taskloop directives.
- Properly handle array section/assumed-size array privatization in C/C++.
- Added support to handle new syntax of the ``uses_allocators`` clause.
- Added support for ``variable-category`` modifier in ``default clause``.
Expand Down
86 changes: 86 additions & 0 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,92 @@ class OMPThreadsetClause final : public OMPClause {
}
};

/// This class represents the 'transparent' clause in the '#pragma omp task'
/// directive.
///
/// \code
/// #pragma omp task transparent(omp_not_impex)
/// \endcode
///
/// In this example, the directive '#pragma omp task' has a 'transparent'
/// clause with OpenMP keyword 'omp_not_impex`. Other valid keywords that may
/// appear in this clause are 'omp_import', 'omp_export' and 'omp_impex'.
///
class OMPTransparentClause final : public OMPClause {
friend class OMPClauseReader;

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

/// A kind of the 'transparent' clause.
OpenMPTransparentKind Kind = OMPC_TRANSPARENT_unknown;

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

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

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

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

public:
/// Build 'transparent' clause with argument \a A ('omp_not_impex',
/// 'omp_import', 'omp_export' or 'omp_impex')
///
/// \param A Argument of the clause ('omp_not_impex', 'omp_import',
/// 'omp_export' or 'omp_impex')
/// \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.
OMPTransparentClause(OpenMPTransparentKind A, SourceLocation ALoc,
SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc)
: OMPClause(llvm::omp::OMPC_transparent, StartLoc, EndLoc),
LParenLoc(LParenLoc), Kind(A), KindLoc(ALoc) {}

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

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

/// Returns kind of the clause.
OpenMPTransparentKind getTransparentKind() const { return Kind; }

/// Returns location of clause kind.
SourceLocation getTransparentKindLoc() 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_transparent;
}
};

/// 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 @@ -3529,6 +3529,12 @@ bool RecursiveASTVisitor<Derived>::VisitOMPThreadsetClause(
return true;
}

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

template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
return true;
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 @@ -107,6 +107,9 @@
#ifndef OPENMP_THREADSET_KIND
#define OPENMP_THREADSET_KIND(Name)
#endif
#ifndef OPENMP_TRANSPARENT_KIND
#define OPENMP_TRANSPARENT_KIND(Name)
#endif

// Static attributes for 'schedule' clause.
OPENMP_SCHEDULE_KIND(static)
Expand Down Expand Up @@ -275,6 +278,11 @@ OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)
OPENMP_THREADSET_KIND(omp_pool)
OPENMP_THREADSET_KIND(omp_team)

OPENMP_TRANSPARENT_KIND(omp_not_impex)
OPENMP_TRANSPARENT_KIND(omp_import)
OPENMP_TRANSPARENT_KIND(omp_export)
OPENMP_TRANSPARENT_KIND(omp_impex)

#undef OPENMP_NUMTASKS_MODIFIER
#undef OPENMP_NUMTHREADS_MODIFIER
#undef OPENMP_DYN_GROUPPRIVATE_MODIFIER
Expand Down Expand Up @@ -307,3 +315,4 @@ OPENMP_THREADSET_KIND(omp_team)
#undef OPENMP_DOACROSS_MODIFIER
#undef OPENMP_ALLOCATE_MODIFIER
#undef OPENMP_THREADSET_KIND
#undef OPENMP_TRANSPARENT_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 @@ -271,6 +271,13 @@ enum OpenMPThreadsetKind {
OMPC_THREADSET_unknown
};

/// OpenMP modifiers for 'transparent' clause.
enum OpenMPTransparentKind {
#define OPENMP_TRANSPARENT_KIND(Name) OMPC_TRANSPARENT_##Name,
#include "clang/Basic/OpenMPKinds.def"
OMPC_TRANSPARENT_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 @@ -981,6 +981,12 @@ class SemaOpenMP : public SemaBase {
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
/// Called on well-formed 'transparent' clause.
OMPClause *ActOnOpenMPTransparentClause(OpenMPTransparentKind 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 @@ -127,6 +127,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
case OMPC_untied:
case OMPC_mergeable:
case OMPC_threadset:
case OMPC_transparent:
case OMPC_threadprivate:
case OMPC_groupprivate:
case OMPC_flush:
Expand Down Expand Up @@ -2045,6 +2046,13 @@ void OMPClausePrinter::VisitOMPThreadsetClause(OMPThreadsetClause *Node) {
<< ")";
}

void OMPClausePrinter::VisitOMPTransparentClause(OMPTransparentClause *Node) {
OS << "transparent("
<< getOpenMPSimpleClauseTypeName(OMPC_transparent,
Node->getTransparentKind())
<< ")";
}

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

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

void OMPClauseProfiler::VisitOMPTransparentClause(
const OMPTransparentClause *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 @@ -229,6 +229,15 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
return OMPC_THREADSET_unknown;
return Type;
}
case OMPC_transparent: {
unsigned Type = llvm::StringSwitch<unsigned>(Str)
#define OPENMP_TRANSPARENT_KIND(Name) .Case(#Name, OMPC_TRANSPARENT_##Name)
#include "clang/Basic/OpenMPKinds.def"
.Default(OMPC_TRANSPARENT_unknown);
if (LangOpts.OpenMP < 60)
return OMPC_TRANSPARENT_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 @@ -608,6 +617,16 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'threadset' clause modifier");
case OMPC_transparent:
switch (Type) {
case OMPC_TRANSPARENT_unknown:
return "unknown";
#define OPENMP_TRANSPARENT_KIND(Name) \
case OMPC_TRANSPARENT_##Name: \
return #Name;
#include "clang/Basic/OpenMPKinds.def"
}
llvm_unreachable("Invalid OpenMP 'transparent' clause modifier");
case OMPC_unknown:
case OMPC_threadprivate:
case OMPC_groupprivate:
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3739,6 +3739,7 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
PriorityFlag = 0x20,
DetachableFlag = 0x40,
FreeAgentFlag = 0x80,
TransparentFlag = 0x100,
};
unsigned Flags = Data.Tied ? TiedFlag : 0;
bool NeedsCleanup = false;
Expand All @@ -3753,6 +3754,9 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
if (Kind == OMPC_THREADSET_omp_pool)
Flags = Flags | FreeAgentFlag;
}
if (D.getSingleClause<OMPTransparentClause>())
Flags |= TransparentFlag;

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 @@ -3223,6 +3223,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective);
break;
case OMPC_threadset:
case OMPC_transparent:
case OMPC_fail:
case OMPC_proc_bind:
case OMPC_atomic_default_mem_order:
Expand Down
22 changes: 22 additions & 0 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17223,6 +17223,11 @@ OMPClause *SemaOpenMP::ActOnOpenMPSimpleClause(
Res = ActOnOpenMPThreadsetClause(static_cast<OpenMPThreadsetKind>(Argument),
ArgumentLoc, StartLoc, LParenLoc, EndLoc);
break;
case OMPC_transparent:
Res = ActOnOpenMPTransparentClause(
static_cast<OpenMPTransparentKind>(Argument), ArgumentLoc, StartLoc,
LParenLoc, EndLoc);
break;
case OMPC_if:
case OMPC_final:
case OMPC_num_threads:
Expand Down Expand Up @@ -17379,6 +17384,23 @@ OMPClause *SemaOpenMP::ActOnOpenMPThreadsetClause(OpenMPThreadsetKind Kind,
OMPThreadsetClause(Kind, KindLoc, StartLoc, LParenLoc, EndLoc);
}

OMPClause *SemaOpenMP::ActOnOpenMPTransparentClause(OpenMPTransparentKind Kind,
SourceLocation KindLoc,
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc) {
if (Kind == OMPC_TRANSPARENT_unknown) {
Diag(KindLoc, diag::err_omp_unexpected_clause_value)
<< getListOfPossibleValues(OMPC_transparent, /*First=*/0,
/*Last=*/unsigned(OMPC_TRANSPARENT_unknown))
<< getOpenMPClauseName(OMPC_transparent);
return nullptr;
}

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

OMPClause *SemaOpenMP::ActOnOpenMPProcBindClause(ProcBindKind Kind,
SourceLocation KindKwLoc,
SourceLocation StartLoc,
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -10637,6 +10637,12 @@ TreeTransform<Derived>::TransformOMPThreadsetClause(OMPThreadsetClause *C) {
return C;
}

template <typename Derived>
OMPClause *
TreeTransform<Derived>::TransformOMPTransparentClause(OMPTransparentClause *C) {
return C;
}

template <typename Derived>
OMPClause *
TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Expand Down
11 changes: 11 additions & 0 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11258,6 +11258,9 @@ OMPClause *OMPClauseReader::readClause() {
case llvm::omp::OMPC_threadset:
C = new (Context) OMPThreadsetClause();
break;
case llvm::omp::OMPC_transparent:
C = new (Context) OMPTransparentClause();
break;
case llvm::omp::OMPC_read:
C = new (Context) OMPReadClause();
break;
Expand Down Expand Up @@ -11675,6 +11678,14 @@ void OMPClauseReader::VisitOMPThreadsetClause(OMPThreadsetClause *C) {
C->setThreadsetKind(TKind);
}

void OMPClauseReader::VisitOMPTransparentClause(OMPTransparentClause *C) {
C->setLParenLoc(Record.readSourceLocation());
SourceLocation TransparentKindLoc = Record.readSourceLocation();
C->setTransparentKindLoc(TransparentKindLoc);
OpenMPTransparentKind TKind = Record.readEnum<OpenMPTransparentKind>();
C->setTransparentKind(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 @@ -7918,6 +7918,12 @@ void OMPClauseWriter::VisitOMPThreadsetClause(OMPThreadsetClause *C) {
Record.writeEnum(C->getThreadsetKind());
}

void OMPClauseWriter::VisitOMPTransparentClause(OMPTransparentClause *C) {
Record.AddSourceLocation(C->getLParenLoc());
Record.AddSourceLocation(C->getTransparentKindLoc());
Record.writeEnum(C->getTransparentKind());
}

void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) {
Record.push_back(unsigned(C->getProcBindKind()));
Record.AddSourceLocation(C->getLParenLoc());
Expand Down
11 changes: 11 additions & 0 deletions clang/test/OpenMP/task_ast_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,21 @@ int main(int argc, char **argv) {
#pragma omp task threadset(omp_pool)
#pragma omp task threadset(omp_team)
foo();

#pragma omp task transparent(omp_not_impex)
#pragma omp task transparent(omp_import)
#pragma omp task transparent(omp_export)
#pragma omp task transparent(omp_impex)
foo();
#endif
// CHECK60: #pragma omp task threadset(omp_pool)
// CHECK60: #pragma omp task threadset(omp_team)
// CHECK60-NEXT: foo();
// CHECK60: #pragma omp task transparent(omp_not_impex)
// CHECK60: #pragma omp task transparent(omp_import)
// CHECK60: #pragma omp task transparent(omp_export)
// CHECK60: #pragma omp task transparent(omp_impex)
// CHECK60-NEXT: foo();
return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
}

Expand Down
Loading