LLVM: lib/Frontend/OpenMP/OMP.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
19
20#include
21#include
22#include
23#include
24#include <type_traits>
25
26using namespace llvm;
28
29#define GEN_DIRECTIVES_IMPL
30#include "llvm/Frontend/OpenMP/OMP.inc"
31
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 auto firstLoopAssociated =
55 for (auto It = List.begin(), End = List.end(); It != End; ++It) {
56 if (getDirectiveAssociation(*It) == Association::LoopNest)
57 return It;
58 }
59 return List.end();
60 };
61
63
64 auto Begin = firstLoopAssociated(Leafs);
65 if (Begin == Leafs.end())
67
68 auto End =
69 firstLoopAssociated(llvm::make_range(std::next(Begin), Leafs.end()));
70 if (End == Leafs.end())
72
73 for (; End != Leafs.end(); ++End) {
74 if (getDirectiveAssociation(*End) != Association::LoopNest)
75 break;
76 }
78}
79
80static void
82 unsigned Version) {
84 for (auto C :
88 }
89
91 Directive::Last_)) {
93 return isAllowedClauseForDirective(D, C, Version);
94 });
95 if (AllowsPrivatizing)
97 }
98}
99
102 auto Idx = static_caststd::size\_t\(D);
103 if (Idx >= Directive_enumSize)
104 return {};
105 const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
106 return ArrayRef(&Row[2], static_cast<int>(Row[1]));
107}
108
111 return Leafs;
112 auto Idx = static_cast<size_t>(D);
113 assert(Idx < Directive_enumSize && "Invalid directive");
114 const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
115
116 return ArrayRef(&Row[0], &Row[0] + 1);
117}
118
122 using IteratorTy = ArrayTy::iterator;
124
125 IteratorTy Iter = Leafs.begin();
126 do {
128
129 for (; Iter != Range.begin(); ++Iter)
131 if (.empty()) {
134 assert(Comp != OMPD_unknown);
136 Iter = Range.end();
137
138
139
140 assert(Iter == Leafs.end() && "Malformed directive");
141 }
142 } while (Iter != Leafs.end());
143
144 return Output;
145}
146
148 if (Parts.empty())
149 return OMPD_unknown;
150
151
152
153
159 else
161 }
162
163
164
165
166
167
168
170 if (GivenLeafs.size() == 1)
171 return GivenLeafs.front();
172 RawLeafs[1] = static_cast<Directive>(GivenLeafs.size());
173
174 auto Iter = std::lower_bound(
175 LeafConstructTable, LeafConstructTableEndDirective,
176 static_cast<std::decay_t<decltype(*LeafConstructTable)>>(RawLeafs.data()),
177 [](const llvm::omp::Directive *RowA, const llvm::omp::Directive *RowB) {
178 const auto *BeginA = &RowA[2];
179 const auto *EndA = BeginA + static_cast(RowA[1]);
180 const auto *BeginB = &RowB[2];
181 const auto *EndB = BeginB + static_cast(RowB[1]);
182 if (BeginA == EndA && BeginB == EndB)
183 return static_cast(RowA[0]) < static_cast(RowB[0]);
184 return std::lexicographical_compare(BeginA, EndA, BeginB, EndB);
185 });
186
187 if (Iter == std::end(LeafConstructTable))
188 return OMPD_unknown;
189
190
193 if (FoundLeafs == GivenLeafs)
194 return Found;
195 return OMPD_unknown;
196}
197
199
202 if (Leafs.size() <= 1)
203 return false;
206}
207
213
215 static unsigned Versions[]{31, 40, 45, 50, 51, 52, 60, 61};
216 return Versions;
217}
218
221 [[maybe_unused]] static bool Init =
223
224
225
226
227
229}
230
232
233 if (FunctionName.ends_with(".internalized"))
234 return FunctionName.drop_back(sizeof("internalized")).str() +
235 " (internalized)";
236 unsigned LineNo = 0;
238 if (LineNo == 0)
239 return FunctionName.str();
240 return ("omp target in " + ParentName + " @ " + std::to_string(LineNo) +
241 " (" + FunctionName + ")")
242 .str();
243}
244
246 unsigned &LineNo) {
247
248
249
250 if (!KernelName.starts_with(TargetRegionEntryInfo::KernelNamePrefix))
251 return "";
252
253 auto PrettyName = KernelName.drop_front(
254 sizeof(TargetRegionEntryInfo::KernelNamePrefix) - 1);
255 for (int I = 0; I < 3; ++I) {
256 PrettyName = PrettyName.drop_while([](char c) { return c != '_'; });
257 PrettyName = PrettyName.drop_front();
258 }
259
260
261 size_t LineIdx = PrettyName.rfind("_l");
263 return "";
264 if (PrettyName.drop_front(LineIdx + 2).consumeInteger(10, LineNo))
265 return "";
266 return demangle(PrettyName.take_front(LineIdx));
267}
268}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static iterator_range< ArrayRef< Directive >::iterator > getFirstCompositeRange(iterator_range< ArrayRef< Directive >::iterator > Leafs)
Definition OMP.cpp:33
static void collectPrivatizingConstructs(llvm::SmallSet< Directive, 16 > &Constructs, unsigned Version)
Definition OMP.cpp:81
Provides some synthesis utilities to produce sequences of values.
This file defines the SmallSet class.
This file defines the SmallVector class.
LocallyHashedType DenseMapInfo< LocallyHashedType >::Empty
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
static constexpr size_t npos
std::string str() const
str - Get the contents as an std::string.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI ArrayRef< unsigned > getOpenMPVersions()
Definition OMP.cpp:214
LLVM_ABI bool isCombinedConstruct(Directive D)
Definition OMP.cpp:208
LLVM_ABI std::string deconstructOpenMPKernelName(StringRef KernelName, unsigned &LineNo)
Deconstruct an OpenMP kernel name into the parent function name and the line number.
Definition OMP.cpp:245
LLVM_ABI ArrayRef< Directive > getLeafOrCompositeConstructs(Directive D, SmallVectorImpl< Directive > &Output)
Definition OMP.cpp:120
bool isPrivatizingConstruct(Directive D, unsigned Version)
Can directive D, under some circumstances, create a private copy of a variable in given OpenMP versio...
Definition OMP.cpp:219
LLVM_ABI bool isCompositeConstruct(Directive D)
Definition OMP.cpp:200
static constexpr bool isPrivatizingClause(Clause C)
LLVM_ABI Directive getCompoundConstruct(ArrayRef< Directive > Parts)
Definition OMP.cpp:147
LLVM_ABI bool isLeafConstruct(Directive D)
Definition OMP.cpp:198
LLVM_ABI ArrayRef< Directive > getLeafConstructsOrSelf(Directive D)
Definition OMP.cpp:109
LLVM_ABI std::string prettifyFunctionName(StringRef FunctionName)
Create a nicer version of a function name for humans to look at.
Definition OMP.cpp:231
LLVM_ABI ArrayRef< Directive > getLeafConstructs(Directive D)
Definition OMP.cpp:101
This is an optimization pass for GlobalISel generic memory operations.
auto enum_seq_inclusive(EnumT Begin, EnumT End)
Iterate over an enum type from Begin to End inclusive.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
ArrayRef(const T &OneElt) -> ArrayRef< T >
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
DEMANGLE_ABI std::string demangle(std::string_view MangledName)
Attempt to demangle a string using different demangling schemes.