26#ifndef LLVM_SUPPORT_AUTOMATON_H
27#define LLVM_SUPPORT_AUTOMATON_H
51 std::make_tuple(
Other.FromDfaState,
Other.ToDfaState);
77 std::deque<PathSegment *> Heads;
83 PathSegment *makePathSegment(
uint64_t State, PathSegment *
Tail) {
94 unsigned NumHeads = Heads.size();
95 for (
unsigned I = 0;
I < NumHeads; ++
I) {
96 PathSegment *Head = Heads[
I];
103 for (; PI != PE; ++PI)
104 if (PI->FromDfaState == Head->State)
105 Heads.push_back(makePathSegment(PI->ToDfaState, Head));
109 Heads.erase(Heads.begin(), std::next(Heads.begin(), NumHeads));
114 : TransitionInfo(TransitionInfo) {
119 return TransitionInfo;
127 Heads.push_back(makePathSegment(0ULL,
nullptr));
131 unsigned EndIdx = TransitionInfoIdx;
132 while (TransitionInfo[EndIdx].ToDfaState != 0)
135 EndIdx - TransitionInfoIdx);
141 for (
auto *Head : Heads) {
143 while (Head->State != 0) {
144 P.push_back(Head->State);
147 std::reverse(
P.begin(),
P.end());
168 using MapTy = std::map<std::pair<uint64_t, ActionT>, std::pair<uint64_t, unsigned>>;
169 std::shared_ptr<MapTy> M;
172 std::shared_ptr<internal::NfaTranscriber> Transcriber;
190 template <
typename InfoT>
193 if (!TranscriptionTable.empty())
195 std::make_shared<internal::NfaTranscriber>(TranscriptionTable);
196 Transcribe = Transcriber !=
nullptr;
197 M = std::make_shared<MapTy>();
198 for (
const auto &
I : Transitions)
200 M->emplace(std::make_pair(
I.FromDfaState,
I.Action),
201 std::make_pair(
I.ToDfaState,
I.InfoIdx));
206 if (
Other.Transcriber)
207 Transcriber = std::make_shared<internal::NfaTranscriber>(
208 Other.Transcriber->getTransitionInfo());
215 Transcriber->reset();
222 "Transcription is only available if TranscriptionTable was provided "
223 "to the Automaton constructor");
234 auto I = M->find({State,
A});
237 if (Transcriber && Transcribe)
238 Transcriber->transition(
I->second.second);
239 State =
I->second.first;
245 auto I = M->find({State,
A});
246 return I != M->end();
253 assert(Transcriber && Transcribe &&
254 "Can only obtain NFA paths if transcribing!");
255 return Transcriber->getPaths();
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file defines the DenseMap class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
A deterministic finite-state automaton.
void reset()
Reset the automaton to its initial state.
bool canAdd(const ActionT &A)
Return true if the automaton can be transitioned based on input symbol A.
Automaton(const Automaton &Other)
bool add(const ActionT &A)
Transition the automaton based on input symbol A.
void enableTranscription(bool Enable=true)
Enable or disable transcription.
ArrayRef< NfaPath > getNfaPaths()
Obtain a set of possible paths through the input nondeterministic automaton that could be obtained fr...
Automaton(ArrayRef< InfoT > Transitions, ArrayRef< NfaStatePair > TranscriptionTable={})
Create an automaton.
void push_back(const T &Elt)
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
The internal class that maintains all possible paths through an NFA based on a path through the DFA.
NfaTranscriber(ArrayRef< NfaStatePair > TransitionInfo)
ArrayRef< NfaPath > getPaths()
void transition(unsigned TransitionInfoIdx)
ArrayRef< NfaStatePair > getTransitionInfo() const
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
This is an optimization pass for GlobalISel generic memory operations.
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Forward define the pair type used by the automata transition info tables.
bool operator<(const NfaStatePair &Other) const