LLVM 24.0.0git
DirectiveNameParser.cpp
Go to the documentation of this file.
1//===- DirectiveNameParser.cpp --------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/ADT/Sequence.h"
12#include "llvm/ADT/StringRef.h"
14
15#include <cassert>
16#include <memory>
17
18namespace llvm::omp {
20 // Take every directive, get its name in every version, break the name up
21 // into whitespace-separated tokens, and insert each token.
22 for (Directive D : directives()) {
23 if (D == Directive::OMPD_unknown || !(getDirectiveLanguages(D) & L))
24 continue;
25 // Parse "ORDERED" as OMPD_ordered_standalone.
26 if (D == OMPD_ordered_blockassoc)
27 continue;
28 for (unsigned Ver : getOpenMPVersions())
29 insertName(getOpenMPDirectiveName(D, Ver), D);
30 }
31}
32
34DirectiveNameParser::consume(const State *Current, StringRef Tok) const {
35 if (!Current)
36 return Current;
37 assert(Current->isValid() && "Invalid input state");
38 if (const State *Next = Current->next(Tok))
39 return Next->isValid() ? Next : nullptr;
40 return nullptr;
41}
42
48
49void DirectiveNameParser::insertName(StringRef Name, Directive D) {
50 State *Where = &InitialState;
51
52 for (StringRef Tok : tokenize(Name))
53 Where = insertTransition(Where, Tok);
54
55 Where->Value = D;
56}
57
58DirectiveNameParser::State *
59DirectiveNameParser::insertTransition(State *From, StringRef Tok) {
60 assert(From && "Expecting state");
61 if (!From->Transition)
62 From->Transition = std::make_unique<State::TransitionMapTy>();
63 if (State *Next = From->next(Tok))
64 return Next;
65
66 auto [Where, DidIt] = From->Transition->try_emplace(Tok, State());
67 assert(DidIt && "Map insertion failed");
68 return &Where->second;
69}
70
71const DirectiveNameParser::State *
72DirectiveNameParser::State::next(StringRef Tok) const {
73 if (!Transition)
74 return nullptr;
75 auto F = Transition->find(Tok);
76 return F != Transition->end() ? &F->second : nullptr;
77}
78
79DirectiveNameParser::State *DirectiveNameParser::State::next(StringRef Tok) {
80 if (!Transition)
81 return nullptr;
82 auto F = Transition->find(Tok);
83 return F != Transition->end() ? &F->second : nullptr;
84}
85} // namespace llvm::omp
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define F(x, y, z)
Definition MD5.cpp:54
Provides some synthesis utilities to produce sequences of values.
This file contains some functions that are useful when dealing with strings.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM_ABI ArrayRef< unsigned > getOpenMPVersions()
Definition OMP.cpp:212
static constexpr auto directives()
Definition OMP.h:170
LLVM_ABI void SplitString(StringRef Source, SmallVectorImpl< StringRef > &OutFragments, StringRef Delimiters=" \t\n\v\f\r")
SplitString - Split up the specified string according to the specified delimiters,...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
static LLVM_ABI SmallVector< StringRef > tokenize(StringRef N)
LLVM_ABI const State * consume(const State *Current, StringRef Tok) const
LLVM_ABI DirectiveNameParser(SourceLanguage L=SourceLanguage::C)