26 #ifndef LLVM_SUPPORT_AUTOMATON_H 27 #define LLVM_SUPPORT_AUTOMATON_H 36 #include <unordered_map> 52 return std::make_tuple(FromDfaState, ToDfaState) <
79 std::deque<PathSegment *> Heads;
85 PathSegment *makePathSegment(uint64_t State, PathSegment *
Tail) {
96 unsigned NumHeads = Heads.size();
97 for (
unsigned I = 0;
I < NumHeads; ++
I) {
98 PathSegment *Head = Heads[
I];
105 for (; PI != PE; ++PI)
106 if (PI->FromDfaState == Head->State)
107 Heads.push_back(makePathSegment(PI->ToDfaState, Head));
111 Heads.erase(Heads.begin(), std::next(Heads.begin(), NumHeads));
116 : TransitionInfo(TransitionInfo) {
121 return TransitionInfo;
129 Heads.push_back(makePathSegment(0ULL,
nullptr));
133 unsigned EndIdx = TransitionInfoIdx;
134 while (TransitionInfo[EndIdx].
ToDfaState != 0)
137 EndIdx - TransitionInfoIdx);
143 for (
auto *Head : Heads) {
145 while (Head->State != 0) {
170 using MapTy = std::map<std::pair<uint64_t, ActionT>, std::pair<uint64_t, unsigned>>;
171 std::shared_ptr<MapTy> M;
174 std::shared_ptr<internal::NfaTranscriber> Transcriber;
192 template <
typename InfoT>
195 if (!TranscriptionTable.empty())
197 std::make_shared<internal::NfaTranscriber>(TranscriptionTable);
198 Transcribe = Transcriber !=
nullptr;
199 M = std::make_shared<MapTy>();
200 for (
const auto &
I : Transitions)
202 M->emplace(std::make_pair(
I.FromDfaState,
I.Action),
203 std::make_pair(
I.ToDfaState,
I.InfoIdx));
206 : M(Other.M), State(Other.State), Transcribe(Other.Transcribe) {
208 if (Other.Transcriber)
209 Transcriber = std::make_shared<internal::NfaTranscriber>(
210 Other.Transcriber->getTransitionInfo());
217 Transcriber->reset();
224 "Transcription is only available if TranscriptionTable was provided " 225 "to the Automaton constructor");
235 bool add(
const ActionT &A) {
236 auto I = M->find({State, A});
239 if (Transcriber && Transcribe)
240 Transcriber->transition(
I->second.second);
241 State =
I->second.first;
247 auto I = M->find({State, A});
248 return I != M->end();
255 assert(Transcriber && Transcribe &&
256 "Can only obtain NFA paths if transcribing!");
257 return Transcriber->getPaths();
263 #endif // LLVM_SUPPORT_AUTOMATON_H auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
This class represents lattice values for constants.
Automaton(ArrayRef< InfoT > Transitions, ArrayRef< NfaStatePair > TranscriptionTable={})
Create an automaton.
void enableTranscription(bool Enable=true)
Enable or disable transcription.
void push_back(const T &Elt)
bool operator<(const NfaStatePair &Other) const
The internal class that maintains all possible paths through an NFA based on a path through the DFA...
ArrayRef< NfaPath > getPaths()
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void DestroyAll()
Call the destructor of each allocated object and deallocate all but the current slab and reset the cu...
bool add(const ActionT &A)
Transition the automaton based on input symbol A.
void reset()
Reset the automaton to its initial state.
T * Allocate(size_t num=1)
Allocate space for an array of objects without constructing them.
Forward define the pair type used by the automata transition info tables.
Automaton(const Automaton &Other)
ArrayRef< NfaPath > getNfaPaths()
Obtain a set of possible paths through the input nondeterministic automaton that could be obtained fr...
bool canAdd(const ActionT &A)
Return true if the automaton can be transitioned based on input symbol A.
ArrayRef< NfaStatePair > getTransitionInfo() const
Tail - This calling convention attemps to make calls as fast as possible while guaranteeing that tail...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void transition(unsigned TransitionInfoIdx)
A deterministic finite-state automaton.
NfaTranscriber(ArrayRef< NfaStatePair > TransitionInfo)
auto upper_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...