Skip to content

Commit 9935ba8

Browse files
committed
[Frontend][OpenMP] Add functions for checking construct type
Implement helper functions to identify leaf, composite, and combined constructs.
1 parent a3efc53 commit 9935ba8

File tree

2 files changed

+28
-0
lines changed
  • llvm

2 files changed

+28
-0
lines changed

llvm/include/llvm/Frontend/OpenMP/OMP.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@
1515

1616
#include "llvm/Frontend/OpenMP/OMP.h.inc"
1717

18+
namespace llvm::omp {
19+
bool isLeafConstruct(Directive D);
20+
bool isCompositeConstruct(Directive D);
21+
bool isCombinedConstruct(Directive D);
22+
} // namespace llvm::omp
23+
1824
#endif // LLVM_FRONTEND_OPENMP_OMP_H

llvm/lib/Frontend/OpenMP/OMP.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "llvm/Frontend/OpenMP/OMP.h"
1010

11+
#include "llvm/ADT/STLExtras.h"
1112
#include "llvm/ADT/StringRef.h"
1213
#include "llvm/ADT/StringSwitch.h"
1314
#include "llvm/Support/ErrorHandling.h"
@@ -17,3 +18,24 @@ using namespace omp;
1718

1819
#define GEN_DIRECTIVES_IMPL
1920
#include "llvm/Frontend/OpenMP/OMP.inc"
21+
22+
namespace llvm::omp {
23+
bool isLeafConstruct(Directive D) { return getLeafConstructs(D).empty(); }
24+
25+
bool isCompositeConstruct(Directive D) {
26+
// OpenMP Spec 5.2: [17.3, 8-9]
27+
// If directive-name-A and directive-name-B both correspond to loop-
28+
// associated constructs then directive-name is a composite construct
29+
size_t numLoopConstructs =
30+
llvm::count_if(getLeafConstructs(D), [](Directive L) {
31+
return getDirectiveAssociation(L) == Association::Loop;
32+
});
33+
return numLoopConstructs > 1;
34+
}
35+
36+
bool isCombinedConstruct(Directive D) {
37+
// OpenMP Spec 5.2: [17.3, 9-10]
38+
// Otherwise directive-name is a combined construct.
39+
return !getLeafConstructs(D).empty() && !isCompositeConstruct(D);
40+
}
41+
} // namespace llvm::omp

0 commit comments

Comments
 (0)