[llvm-branch-commits] [flang] [flang][OpenMP] Use new modifiers in IF/LASTPRIVATE (PR #118128)
Krzysztof Parzyszek via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Dec 2 06:09:18 PST 2024
================
@@ -16,13 +16,58 @@
#include "token-parsers.h"
#include "type-parser-implementation.h"
#include "flang/Parser/parse-tree.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Frontend/OpenMP/OMP.h"
// OpenMP Directives and Clauses
namespace Fortran::parser {
constexpr auto startOmpLine = skipStuffBeforeStatement >> "!$OMP "_sptok;
constexpr auto endOmpLine = space >> endOfLine;
+/// Parse OpenMP directive name (this includes compound directives).
+struct OmpDirectiveNameParser {
+ using resultType = llvm::omp::Directive;
+ using Token = TokenStringMatch<false, false>;
+
+ std::optional<resultType> Parse(ParseState &state) const {
+ for (const NameWithId &nid : directives()) {
+ if (attempt(Token(nid.first.data())).Parse(state)) {
+ return nid.second;
+ }
+ }
+ return std::nullopt;
+ }
+
+private:
+ using NameWithId = std::pair<std::string, llvm::omp::Directive>;
+
+ llvm::iterator_range<const NameWithId *> directives() const;
+ void initTokens(NameWithId *) const;
+};
+
+llvm::iterator_range<const OmpDirectiveNameParser::NameWithId *>
+OmpDirectiveNameParser::directives() const {
+ static NameWithId table[llvm::omp::Directive_enumSize];
+ [[maybe_unused]] static bool init = (initTokens(table), true);
----------------
kparzysz wrote:
The issue here is with thread-safety. Starting with C++11, the standard guarantees that local statics are initialized in a thread-safe manner, that is, that the initializer code is only executed by a single thread. Hence the "trick" is to make the preparation of a local static be a part of the initializer. This is a de facto standard in the LLVM code, although I didn't see it mentioned in the coding guidelines. It's somewhat rare, but within the set of use cases it's the preferred solution.
https://github.com/llvm/llvm-project/pull/118128
More information about the llvm-branch-commits
mailing list