mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
rose: clean up nfa state alloc
This commit is contained in:
parent
246f9f4f86
commit
10aa806d67
@ -2105,16 +2105,14 @@ bool buildNfas(RoseBuildImpl &tbi, build_context &bc, QueueIndexFactory &qif,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void allocateStateSpace(const NFA *nfa, const set<u32> &transient_queues,
|
void allocateStateSpace(const NFA *nfa, NfaInfo *nfa_info, bool is_transient,
|
||||||
RoseStateOffsets *so, NfaInfo *nfa_infos,
|
RoseStateOffsets *so, u32 *currFullStateSize,
|
||||||
u32 *currFullStateSize, u32 *maskStateSize,
|
u32 *maskStateSize, u32 *tStateSize) {
|
||||||
u32 *tStateSize) {
|
const u32 stateSize = nfa->streamStateSize;
|
||||||
u32 qi = nfa->queueIndex;
|
const u32 scratchStateSize = nfa->scratchStateSize;
|
||||||
bool transient = transient_queues.find(qi) != transient_queues.end();
|
|
||||||
u32 stateSize = verify_u32(nfa->streamStateSize);
|
|
||||||
|
|
||||||
u32 state_offset;
|
u32 state_offset;
|
||||||
if (transient) {
|
if (is_transient) {
|
||||||
state_offset = *tStateSize;
|
state_offset = *tStateSize;
|
||||||
*tStateSize += stateSize;
|
*tStateSize += stateSize;
|
||||||
} else {
|
} else {
|
||||||
@ -2124,29 +2122,30 @@ void allocateStateSpace(const NFA *nfa, const set<u32> &transient_queues,
|
|||||||
*maskStateSize += stateSize;
|
*maskStateSize += stateSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
nfa_infos[qi].stateOffset = state_offset;
|
nfa_info->stateOffset = state_offset;
|
||||||
|
|
||||||
// Uncompressed state must be aligned.
|
// Uncompressed state must be aligned.
|
||||||
u32 scratchStateSize = verify_u32(nfa->scratchStateSize);
|
|
||||||
u32 alignReq = state_alignment(*nfa);
|
u32 alignReq = state_alignment(*nfa);
|
||||||
assert(alignReq);
|
assert(alignReq);
|
||||||
while (*currFullStateSize % alignReq) {
|
while (*currFullStateSize % alignReq) {
|
||||||
(*currFullStateSize)++;
|
(*currFullStateSize)++;
|
||||||
}
|
}
|
||||||
nfa_infos[qi].fullStateOffset = *currFullStateSize;
|
nfa_info->fullStateOffset = *currFullStateSize;
|
||||||
*currFullStateSize += scratchStateSize;
|
*currFullStateSize += scratchStateSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void findTransientQueues(const map<RoseVertex, left_build_info> &leftfix_info,
|
set<u32>
|
||||||
set<u32> *out) {
|
findTransientQueues(const map<RoseVertex, left_build_info> &leftfix_info) {
|
||||||
DEBUG_PRINTF("curating transient queues\n");
|
DEBUG_PRINTF("curating transient queues\n");
|
||||||
for (const auto &build : leftfix_info | map_values) {
|
set<u32> out;
|
||||||
if (build.transient) {
|
for (const auto &left : leftfix_info | map_values) {
|
||||||
DEBUG_PRINTF("q %u is transient\n", build.queue);
|
if (left.transient) {
|
||||||
out->insert(build.queue);
|
DEBUG_PRINTF("q %u is transient\n", left.queue);
|
||||||
|
out.insert(left.queue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -2167,12 +2166,14 @@ void updateNfaState(const build_context &bc, RoseEngine &proto,
|
|||||||
*tStateSize = 0;
|
*tStateSize = 0;
|
||||||
*fullStateSize = 0;
|
*fullStateSize = 0;
|
||||||
|
|
||||||
set<u32> transient_queues;
|
auto transient_queues = findTransientQueues(bc.leftfix_info);
|
||||||
findTransientQueues(bc.leftfix_info, &transient_queues);
|
|
||||||
|
|
||||||
for (const auto &m : bc.engineOffsets) {
|
for (const auto &m : bc.engineOffsets) {
|
||||||
const NFA *n = get_nfa_from_blob(bc, m.first);
|
const NFA *nfa = get_nfa_from_blob(bc, m.first);
|
||||||
allocateStateSpace(n, transient_queues, so, nfa_infos, fullStateSize,
|
u32 qi = nfa->queueIndex;
|
||||||
|
bool is_transient = contains(transient_queues, qi);
|
||||||
|
NfaInfo *nfa_info = &nfa_infos[qi];
|
||||||
|
allocateStateSpace(nfa, nfa_info, is_transient, so, fullStateSize,
|
||||||
nfaStateSize, tStateSize);
|
nfaStateSize, tStateSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user