mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-07-12 21:44:44 +03:00
dfa: allow smwr to avoid lengthy daddy recalc
This commit is contained in:
parent
1538d90a9e
commit
beac58fcb4
@ -802,9 +802,9 @@ flat_set<dstate_id_t> find_daddy_candidates(const dfa_info &info,
|
||||
#define MAX_SHERMAN_SELF_LOOP 20
|
||||
|
||||
static
|
||||
void find_better_daddy(dfa_info &info, dstate_id_t curr_id,
|
||||
bool using8bit, bool any_cyclic_near_anchored_state,
|
||||
const Grey &grey) {
|
||||
void find_better_daddy(dfa_info &info, dstate_id_t curr_id, bool using8bit,
|
||||
bool any_cyclic_near_anchored_state,
|
||||
bool trust_daddy_states, const Grey &grey) {
|
||||
if (!grey.allowShermanStates) {
|
||||
return;
|
||||
}
|
||||
@ -839,7 +839,12 @@ void find_better_daddy(dfa_info &info, dstate_id_t curr_id,
|
||||
dstate_id_t best_daddy = 0;
|
||||
dstate &currState = info.states[curr_id];
|
||||
|
||||
const auto hinted = find_daddy_candidates(info, curr_id);
|
||||
flat_set<dstate_id_t> hinted;
|
||||
if (trust_daddy_states) {
|
||||
hinted.insert(currState.daddy);
|
||||
} else {
|
||||
hinted = find_daddy_candidates(info, curr_id);
|
||||
}
|
||||
|
||||
for (const dstate_id_t &donor : hinted) {
|
||||
assert(donor < curr_id);
|
||||
@ -947,6 +952,7 @@ bool is_cyclic_near(const raw_dfa &raw, dstate_id_t root) {
|
||||
|
||||
bytecode_ptr<NFA> mcclellanCompile_i(raw_dfa &raw, accel_dfa_build_strat &strat,
|
||||
const CompileContext &cc,
|
||||
bool trust_daddy_states,
|
||||
set<dstate_id_t> *accel_states) {
|
||||
u16 total_daddy = 0;
|
||||
dfa_info info(strat);
|
||||
@ -963,7 +969,7 @@ bytecode_ptr<NFA> mcclellanCompile_i(raw_dfa &raw, accel_dfa_build_strat &strat,
|
||||
|
||||
for (u32 i = 0; i < info.size(); i++) {
|
||||
find_better_daddy(info, i, using8bit, any_cyclic_near_anchored_state,
|
||||
cc.grey);
|
||||
trust_daddy_states, cc.grey);
|
||||
total_daddy += info.extra[i].daddytaken;
|
||||
}
|
||||
|
||||
@ -989,9 +995,10 @@ bytecode_ptr<NFA> mcclellanCompile_i(raw_dfa &raw, accel_dfa_build_strat &strat,
|
||||
bytecode_ptr<NFA> mcclellanCompile(raw_dfa &raw, const CompileContext &cc,
|
||||
const ReportManager &rm,
|
||||
bool only_accel_init,
|
||||
bool trust_daddy_states,
|
||||
set<dstate_id_t> *accel_states) {
|
||||
mcclellan_build_strat mbs(raw, rm, only_accel_init);
|
||||
return mcclellanCompile_i(raw, mbs, cc, accel_states);
|
||||
return mcclellanCompile_i(raw, mbs, cc, trust_daddy_states, accel_states);
|
||||
}
|
||||
|
||||
size_t mcclellan_build_strat::accelSize(void) const {
|
||||
|
@ -71,12 +71,13 @@ private:
|
||||
bytecode_ptr<NFA>
|
||||
mcclellanCompile(raw_dfa &raw, const CompileContext &cc,
|
||||
const ReportManager &rm, bool only_accel_init,
|
||||
bool trust_daddy_states = false,
|
||||
std::set<dstate_id_t> *accel_states = nullptr);
|
||||
|
||||
/* used internally by mcclellan/haig/gough compile process */
|
||||
bytecode_ptr<NFA>
|
||||
mcclellanCompile_i(raw_dfa &raw, accel_dfa_build_strat &strat,
|
||||
const CompileContext &cc,
|
||||
const CompileContext &cc, bool trust_daddy_states = false,
|
||||
std::set<dstate_id_t> *accel_states = nullptr);
|
||||
|
||||
/**
|
||||
|
@ -692,18 +692,20 @@ bool is_slow(const raw_dfa &rdfa, const set<dstate_id_t> &accel,
|
||||
|
||||
static
|
||||
bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, const CompileContext &cc,
|
||||
const ReportManager &rm, bool has_literals,
|
||||
const ReportManager &rm, bool has_non_literals,
|
||||
set<dstate_id_t> &accel_states) {
|
||||
// If we determinised literals, then we only need to consider the init
|
||||
// If we determinised only literals, then we only need to consider the init
|
||||
// states for acceleration.
|
||||
bool only_accel_init = has_literals;
|
||||
bool only_accel_init = !has_non_literals;
|
||||
bool trust_daddy_states = !has_non_literals;
|
||||
|
||||
bytecode_ptr<NFA> dfa = nullptr;
|
||||
if (cc.grey.allowSmallWriteSheng) {
|
||||
dfa = shengCompile(rdfa, cc, rm, only_accel_init, &accel_states);
|
||||
}
|
||||
if (!dfa) {
|
||||
dfa = mcclellanCompile(rdfa, cc, rm, only_accel_init, &accel_states);
|
||||
dfa = mcclellanCompile(rdfa, cc, rm, only_accel_init,
|
||||
trust_daddy_states, &accel_states);
|
||||
}
|
||||
return dfa;
|
||||
}
|
||||
@ -711,14 +713,14 @@ bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, const CompileContext &cc,
|
||||
static
|
||||
bytecode_ptr<NFA> prepEngine(raw_dfa &rdfa, u32 roseQuality,
|
||||
const CompileContext &cc, const ReportManager &rm,
|
||||
bool has_literals, u32 *start_offset,
|
||||
bool has_non_literals, u32 *start_offset,
|
||||
u32 *small_region) {
|
||||
*start_offset = remove_leading_dots(rdfa);
|
||||
|
||||
// Unleash the McClellan!
|
||||
set<dstate_id_t> accel_states;
|
||||
|
||||
auto nfa = getDfa(rdfa, cc, rm, has_literals, accel_states);
|
||||
auto nfa = getDfa(rdfa, cc, rm, has_non_literals, accel_states);
|
||||
if (!nfa) {
|
||||
DEBUG_PRINTF("DFA compile failed for smallwrite NFA\n");
|
||||
return nullptr;
|
||||
@ -737,7 +739,7 @@ bytecode_ptr<NFA> prepEngine(raw_dfa &rdfa, u32 roseQuality,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nfa = getDfa(rdfa, cc, rm, has_literals, accel_states);
|
||||
nfa = getDfa(rdfa, cc, rm, has_non_literals, accel_states);
|
||||
if (!nfa) {
|
||||
DEBUG_PRINTF("DFA compile failed for smallwrite NFA\n");
|
||||
assert(0); /* able to build orig dfa but not the trimmed? */
|
||||
@ -768,6 +770,7 @@ unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(size_t num_patterns,
|
||||
|
||||
bytecode_ptr<SmallWriteEngine> SmallWriteBuildImpl::build(u32 roseQuality) {
|
||||
const bool has_literals = !is_empty(lit_trie) || !is_empty(lit_trie_nocase);
|
||||
const bool has_non_literals = rdfa != nullptr;
|
||||
if (!rdfa && !has_literals) {
|
||||
DEBUG_PRINTF("no smallwrite engine\n");
|
||||
poisoned = true;
|
||||
@ -788,7 +791,7 @@ bytecode_ptr<SmallWriteEngine> SmallWriteBuildImpl::build(u32 roseQuality) {
|
||||
|
||||
u32 start_offset;
|
||||
u32 small_region;
|
||||
auto nfa = prepEngine(*rdfa, roseQuality, cc, rm, has_literals,
|
||||
auto nfa = prepEngine(*rdfa, roseQuality, cc, rm, has_non_literals,
|
||||
&start_offset, &small_region);
|
||||
if (!nfa) {
|
||||
DEBUG_PRINTF("some smallwrite outfix could not be prepped\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user