[Clang][OpenMP] Add interchange directive by Meinersbur · Pull Request #93022 · llvm/llvm-project (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

@Meinersbur

Add the interchange directive which will be introduced in the upcoming OpenMP 6.0 specification. A preview has been published in Technical Report 12.

@Meinersbur

@Meinersbur

@Meinersbur

@Meinersbur

@Meinersbur

@Meinersbur

@Meinersbur

… users/meinersbur/clang_openmp_reverse

@Meinersbur

@llvmbot

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-flang-openmp

Author: Michael Kruse (Meinersbur)

Changes

Add the interchange directive which will be introduced in the upcoming OpenMP 6.0 specification. A preview has been published in Technical Report 12.


Patch is 185.81 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/93022.diff

30 Files Affected:

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index c7d63818ece23..a79aafbf20222 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -2150,6 +2150,10 @@ enum CXCursorKind { */ CXCursor_OMPReverseDirective = 307,

+DEF_TRAVERSE_STMT(OMPInterchangeDirective,

diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h index fb7f413162fad..01c8b8e1a9f5e 100644 --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -1009,7 +1009,7 @@ class OMPLoopTransformationDirective : public OMPLoopBasedDirective { static bool classof(const Stmt *T) { Stmt::StmtClass C = T->getStmtClass(); return C == OMPTileDirectiveClass || C == OMPUnrollDirectiveClass ||

@@ -5777,6 +5777,80 @@ class OMPReverseDirective final : public OMPLoopTransformationDirective { } };

+/// Represents the '#pragma omp interchange' loop transformation directive. +/// +/// \code{c} +/// #pragma omp interchange +/// for (int i = 0; i < m; ++i) +/// for (int j = 0; j < n; ++j) +/// .. +/// \endcode +class OMPInterchangeDirective final : public OMPLoopTransformationDirective {

}

+OMPInterchangeDirective *OMPInterchangeDirective::Create(

+} + OMPForSimdDirective * OMPForSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 64b481f680311..64bee75b205ae 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -768,6 +768,11 @@ void StmtPrinter::VisitOMPReverseDirective(OMPReverseDirective *Node) { PrintOMPExecutableDirective(Node); }

+void StmtPrinter::VisitOMPInterchangeDirective(OMPInterchangeDirective *Node) {

+void StmtProfiler::VisitOMPInterchangeDirective(

}

bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) { @@ -809,6 +810,7 @@ void clang::getOpenMPCaptureRegions( case OMPD_tile: case OMPD_unroll: case OMPD_reverse:

case Stmt::OMPForDirectiveClass: EmitOMPForDirective(cast(*S)); break; diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index ad6c044aa483b..7a37e452fb559 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -189,6 +189,9 @@ class OMPLoopScope : public CodeGenFunction::RunCleanupsScope { PreInits = Unroll->getPreInits(); } else if (const auto *Reverse = dyn_cast(&S)) { PreInits = Reverse->getPreInits();

+void CodeGenFunction::EmitOMPInterchangeDirective(

diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index ac738e1e82886..c2a8e65ca2d0a 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -3808,6 +3808,7 @@ class CodeGenFunction : public CodeGenTypeCache { void EmitOMPTileDirective(const OMPTileDirective &S); void EmitOMPUnrollDirective(const OMPUnrollDirective &S); void EmitOMPReverseDirective(const OMPReverseDirective &S);

#include "llvm/ADT/IndexedMap.h" #include "llvm/ADT/PointerEmbeddedInt.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/Sequence.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Frontend/OpenMP/OMPAssume.h" @@ -4335,6 +4336,7 @@ void SemaOpenMP::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, case OMPD_tile: case OMPD_unroll: case OMPD_reverse:

case OMPD_for: Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); @@ -15139,6 +15145,8 @@ bool SemaOpenMP::checkTransformableLoopNest( DependentPreInits = Dir->getPreInits(); else if (auto *Dir = dyn_cast(Transform)) DependentPreInits = Dir->getPreInits();

@@ -15937,6 +15945,160 @@ StmtResult SemaOpenMP::ActOnOpenMPReverseDirective(Stmt *AStmt, buildPreInits(Context, PreInits)); }

+StmtResult SemaOpenMP::ActOnOpenMPInterchangeDirective(

[truncated]

@llvmbot

@llvm/pr-subscribers-clang-modules

Author: Michael Kruse (Meinersbur)

Changes

Add the interchange directive which will be introduced in the upcoming OpenMP 6.0 specification. A preview has been published in Technical Report 12.


Patch is 185.81 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/93022.diff

30 Files Affected:

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index c7d63818ece23..a79aafbf20222 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -2150,6 +2150,10 @@ enum CXCursorKind { */ CXCursor_OMPReverseDirective = 307,

+DEF_TRAVERSE_STMT(OMPInterchangeDirective,

diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h index fb7f413162fad..01c8b8e1a9f5e 100644 --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -1009,7 +1009,7 @@ class OMPLoopTransformationDirective : public OMPLoopBasedDirective { static bool classof(const Stmt *T) { Stmt::StmtClass C = T->getStmtClass(); return C == OMPTileDirectiveClass || C == OMPUnrollDirectiveClass ||

@@ -5777,6 +5777,80 @@ class OMPReverseDirective final : public OMPLoopTransformationDirective { } };

+/// Represents the '#pragma omp interchange' loop transformation directive. +/// +/// \code{c} +/// #pragma omp interchange +/// for (int i = 0; i < m; ++i) +/// for (int j = 0; j < n; ++j) +/// .. +/// \endcode +class OMPInterchangeDirective final : public OMPLoopTransformationDirective {

}

+OMPInterchangeDirective *OMPInterchangeDirective::Create(

+} + OMPForSimdDirective * OMPForSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 64b481f680311..64bee75b205ae 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -768,6 +768,11 @@ void StmtPrinter::VisitOMPReverseDirective(OMPReverseDirective *Node) { PrintOMPExecutableDirective(Node); }

+void StmtPrinter::VisitOMPInterchangeDirective(OMPInterchangeDirective *Node) {

+void StmtProfiler::VisitOMPInterchangeDirective(

}

bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) { @@ -809,6 +810,7 @@ void clang::getOpenMPCaptureRegions( case OMPD_tile: case OMPD_unroll: case OMPD_reverse:

case Stmt::OMPForDirectiveClass: EmitOMPForDirective(cast(*S)); break; diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index ad6c044aa483b..7a37e452fb559 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -189,6 +189,9 @@ class OMPLoopScope : public CodeGenFunction::RunCleanupsScope { PreInits = Unroll->getPreInits(); } else if (const auto *Reverse = dyn_cast(&S)) { PreInits = Reverse->getPreInits();

+void CodeGenFunction::EmitOMPInterchangeDirective(

diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index ac738e1e82886..c2a8e65ca2d0a 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -3808,6 +3808,7 @@ class CodeGenFunction : public CodeGenTypeCache { void EmitOMPTileDirective(const OMPTileDirective &S); void EmitOMPUnrollDirective(const OMPUnrollDirective &S); void EmitOMPReverseDirective(const OMPReverseDirective &S);

#include "llvm/ADT/IndexedMap.h" #include "llvm/ADT/PointerEmbeddedInt.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/Sequence.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Frontend/OpenMP/OMPAssume.h" @@ -4335,6 +4336,7 @@ void SemaOpenMP::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, case OMPD_tile: case OMPD_unroll: case OMPD_reverse:

case OMPD_for: Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); @@ -15139,6 +15145,8 @@ bool SemaOpenMP::checkTransformableLoopNest( DependentPreInits = Dir->getPreInits(); else if (auto *Dir = dyn_cast(Transform)) DependentPreInits = Dir->getPreInits();

@@ -15937,6 +15945,160 @@ StmtResult SemaOpenMP::ActOnOpenMPReverseDirective(Stmt *AStmt, buildPreInits(Context, PreInits)); }

+StmtResult SemaOpenMP::ActOnOpenMPInterchangeDirective(

[truncated]

@llvmbot

@llvm/pr-subscribers-clang

Author: Michael Kruse (Meinersbur)

Changes

Add the interchange directive which will be introduced in the upcoming OpenMP 6.0 specification. A preview has been published in Technical Report 12.


Patch is 185.81 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/93022.diff

30 Files Affected:

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index c7d63818ece23..a79aafbf20222 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -2150,6 +2150,10 @@ enum CXCursorKind { */ CXCursor_OMPReverseDirective = 307,

+DEF_TRAVERSE_STMT(OMPInterchangeDirective,

diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h index fb7f413162fad..01c8b8e1a9f5e 100644 --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -1009,7 +1009,7 @@ class OMPLoopTransformationDirective : public OMPLoopBasedDirective { static bool classof(const Stmt *T) { Stmt::StmtClass C = T->getStmtClass(); return C == OMPTileDirectiveClass || C == OMPUnrollDirectiveClass ||

@@ -5777,6 +5777,80 @@ class OMPReverseDirective final : public OMPLoopTransformationDirective { } };

+/// Represents the '#pragma omp interchange' loop transformation directive. +/// +/// \code{c} +/// #pragma omp interchange +/// for (int i = 0; i < m; ++i) +/// for (int j = 0; j < n; ++j) +/// .. +/// \endcode +class OMPInterchangeDirective final : public OMPLoopTransformationDirective {

}

+OMPInterchangeDirective *OMPInterchangeDirective::Create(

+} + OMPForSimdDirective * OMPForSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 64b481f680311..64bee75b205ae 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -768,6 +768,11 @@ void StmtPrinter::VisitOMPReverseDirective(OMPReverseDirective *Node) { PrintOMPExecutableDirective(Node); }

+void StmtPrinter::VisitOMPInterchangeDirective(OMPInterchangeDirective *Node) {

+void StmtProfiler::VisitOMPInterchangeDirective(

}

bool clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) { @@ -809,6 +810,7 @@ void clang::getOpenMPCaptureRegions( case OMPD_tile: case OMPD_unroll: case OMPD_reverse:

case Stmt::OMPForDirectiveClass: EmitOMPForDirective(cast(*S)); break; diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index ad6c044aa483b..7a37e452fb559 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -189,6 +189,9 @@ class OMPLoopScope : public CodeGenFunction::RunCleanupsScope { PreInits = Unroll->getPreInits(); } else if (const auto *Reverse = dyn_cast(&S)) { PreInits = Reverse->getPreInits();

+void CodeGenFunction::EmitOMPInterchangeDirective(

diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index ac738e1e82886..c2a8e65ca2d0a 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -3808,6 +3808,7 @@ class CodeGenFunction : public CodeGenTypeCache { void EmitOMPTileDirective(const OMPTileDirective &S); void EmitOMPUnrollDirective(const OMPUnrollDirective &S); void EmitOMPReverseDirective(const OMPReverseDirective &S);

#include "llvm/ADT/IndexedMap.h" #include "llvm/ADT/PointerEmbeddedInt.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/Sequence.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Frontend/OpenMP/OMPAssume.h" @@ -4335,6 +4336,7 @@ void SemaOpenMP::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, case OMPD_tile: case OMPD_unroll: case OMPD_reverse:

case OMPD_for: Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); @@ -15139,6 +15145,8 @@ bool SemaOpenMP::checkTransformableLoopNest( DependentPreInits = Dir->getPreInits(); else if (auto *Dir = dyn_cast(Transform)) DependentPreInits = Dir->getPreInits();

@@ -15937,6 +15945,160 @@ StmtResult SemaOpenMP::ActOnOpenMPReverseDirective(Stmt *AStmt, buildPreInits(Context, PreInits)); }

+StmtResult SemaOpenMP::ActOnOpenMPInterchangeDirective(

[truncated]

alexey-bataev

Choose a reason for hiding this comment

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

LG with a nit

@Meinersbur

@Meinersbur

@Meinersbur

…rsbur/clang_openmp_interchange

@Meinersbur

Base automatically changed from users/meinersbur/clang_openmp_reverse to main

July 18, 2024 08:35

alexey-bataev

Choose a reason for hiding this comment

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

LG with some nits

"Single-dimensional loop iteration space expected");
auto *OrigCntVar = cast(LoopHelper.Counters.front());
std::string OrigVarName = OrigCntVar->getNameInfo().getAsString();

Choose a reason for hiding this comment

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

SmallString

Choose a reason for hiding this comment

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

I don't get this. getAsString returns an std::string r-value. Assigning it to a SmallString will unpack that std::string and copy it over to SmallString's buffer, compared to RVO where no copy happens other than the initial construction of the std::string inside getAsString().

Furthermore, contemporary implementations of std::string are already using a small-size buffer.

I guess I could call OrigCntVar->getNameInfo().operator<<, and pass a raw_svector_ostream instantiated using a SmallString. This would enable us to choose a larger small buffer size ourselves. Is that what you are asking? If so, what should the small buffer size be?

Choose a reason for hiding this comment

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

Just saying, that better to use SmallString where possible. If you think, std::string is good enough here, I'm fine with it. It was just a suggestion.

assert(IVTy->isIntegerType() &&
"Expected the logical iteration counter to be an integer");
std::string OrigVarName = OrigCntVar->getNameInfo().getAsString();

Choose a reason for hiding this comment

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

SmallString

@Meinersbur Meinersbur deleted the users/meinersbur/clang_openmp_interchange branch

July 19, 2024 07:24

@Meinersbur Meinersbur restored the users/meinersbur/clang_openmp_interchange branch

July 19, 2024 07:27

Labels