rose: move roseRunProgram into its own unit

The roseRunProgram function had gotten very large for the number of
sites it was being inlined into, with negative effects on performance in
large cases. This change moves it into its own translation unit.
This commit is contained in:
Justin Viiret 2016-06-22 16:23:36 +10:00 committed by Matthew Barr
parent f166bc5658
commit 76d96809f8
8 changed files with 1549 additions and 1503 deletions

View File

@ -500,6 +500,7 @@ set (hs_exec_SRCS
src/rose/match.h
src/rose/match.c
src/rose/miracle.h
src/rose/program_runtime.c
src/rose/program_runtime.h
src/rose/runtime.h
src/rose/rose.h

View File

@ -179,15 +179,12 @@ void roseBlockEodExec(const struct RoseEngine *t, u64a offset,
const u64a som = 0;
const size_t match_len = 0;
const char in_anchored = 0;
const char in_catchup = 0;
const char from_mpv = 0;
const char skip_mpv_catchup = 1;
const u8 flags = ROSE_PROG_FLAG_SKIP_MPV_CATCHUP;
// Note: we ignore the result, as this is the last thing to ever happen on
// a scan.
roseRunProgram(t, scratch, t->eodProgramOffset, som, offset, match_len,
in_anchored, in_catchup, from_mpv, skip_mpv_catchup);
flags);
}
/**

View File

@ -39,6 +39,7 @@
#include "nfa/mpv.h"
#include "som/som_runtime.h"
#include "util/fatbit.h"
#include "report.h"
typedef struct queue_match PQ_T;
#define PQ_COMP(pqc_items, a, b) ((pqc_items)[a].loc < (pqc_items)[b].loc)
@ -51,10 +52,12 @@ int roseNfaRunProgram(const struct RoseEngine *rose, struct hs_scratch *scratch,
u64a som, u64a offset, ReportID id, const char from_mpv) {
const u32 program = id;
const size_t match_len = 0; // Unused in this path.
const char in_anchored = 0;
const char in_catchup = 1;
roseRunProgram(rose, scratch, program, som, offset, match_len, in_anchored,
in_catchup, from_mpv, 0);
u8 flags = ROSE_PROG_FLAG_IN_CATCHUP;
if (from_mpv) {
flags |= ROSE_PROG_FLAG_FROM_MPV;
}
roseRunProgram(rose, scratch, program, som, offset, match_len, flags);
return can_stop_matching(scratch) ? MO_HALT_MATCHING : MO_CONTINUE_MATCHING;
}

View File

@ -27,14 +27,9 @@
*/
#include "catchup.h"
#include "counting_miracle.h"
#include "infix.h"
#include "match.h"
#include "miracle.h"
#include "program_runtime.h"
#include "rose_program.h"
#include "rose.h"
#include "som/som_runtime.h"
#include "util/bitutils.h"
#include "util/fatbit.h"
@ -98,13 +93,9 @@ hwlmcb_rv_t roseDelayRebuildCallback(size_t start, size_t end, u32 id,
if (program) {
const u64a som = 0;
const size_t match_len = end - start + 1;
const char in_anchored = 0;
const char in_catchup = 0;
const char from_mpv = 0;
const char skip_mpv_catchup = 0;
UNUSED hwlmcb_rv_t rv =
roseRunProgram(t, scratch, program, som, real_end, match_len,
in_anchored, in_catchup, from_mpv, skip_mpv_catchup);
const u8 flags = 0;
UNUSED hwlmcb_rv_t rv = roseRunProgram(t, scratch, program, som,
real_end, match_len, flags);
assert(rv != HWLM_TERMINATE_MATCHING);
}
@ -253,13 +244,9 @@ int roseAnchoredCallback(u64a end, u32 id, void *ctx) {
const u32 *programs = getByOffset(t, t->litProgramOffset);
assert(id < t->literalCount);
const u64a som = 0;
const char in_anchored = 1;
const char in_catchup = 0;
const char from_mpv = 0;
const char skip_mpv_catchup = 0;
const u8 flags = ROSE_PROG_FLAG_IN_ANCHORED;
if (roseRunProgram(t, scratch, programs[id], som, real_end, match_len,
in_anchored, in_catchup, from_mpv,
skip_mpv_catchup) == HWLM_TERMINATE_MATCHING) {
flags) == HWLM_TERMINATE_MATCHING) {
assert(can_stop_matching(scratch));
DEBUG_PRINTF("caller requested termination\n");
return MO_HALT_MATCHING;
@ -284,12 +271,8 @@ hwlmcb_rv_t roseProcessMatch(const struct RoseEngine *t,
const u32 *programs = getByOffset(t, t->litProgramOffset);
assert(id < t->literalCount);
const u64a som = 0;
const char in_anchored = 0;
const char in_catchup = 0;
const char from_mpv = 0;
const char skip_mpv_catchup = 0;
return roseRunProgram(t, scratch, programs[id], som, end, match_len,
in_anchored, in_catchup, from_mpv, skip_mpv_catchup);
const u8 flags = 0;
return roseRunProgram(t, scratch, programs[id], som, end, match_len, flags);
}
static rose_inline
@ -594,12 +577,9 @@ hwlmcb_rv_t rosePureLiteralCallback(size_t start, size_t end, u32 id,
const struct RoseEngine *rose = ci->rose;
const u32 *programs = getByOffset(rose, rose->litProgramOffset);
assert(id < rose->literalCount);
const char in_anchored = 0;
const char in_catchup = 0;
const char from_mpv = 0;
const char skip_mpv_catchup = 0;
const u8 flags = 0;
return roseRunProgram(rose, scratch, programs[id], som, real_end, match_len,
in_anchored, in_catchup, from_mpv, skip_mpv_catchup);
flags);
}
/**
@ -635,13 +615,9 @@ int roseRunBoundaryProgram(const struct RoseEngine *rose, u32 program,
const u64a som = 0;
const size_t match_len = 0;
const char in_anchored = 0;
const char in_catchup = 0;
const char from_mpv = 0;
const char skip_mpv_catchup = 0;
hwlmcb_rv_t rv =
roseRunProgram(rose, scratch, program, som, stream_offset, match_len,
in_anchored, in_catchup, from_mpv, skip_mpv_catchup);
const u8 flags = 0;
hwlmcb_rv_t rv = roseRunProgram(rose, scratch, program, som, stream_offset,
match_len, flags);
if (rv == HWLM_TERMINATE_MATCHING) {
return MO_HALT_MATCHING;
}
@ -659,13 +635,9 @@ int roseReportAdaptor_i(u64a som, u64a offset, ReportID id, void *context) {
// Our match ID is the program offset.
const u32 program = id;
const size_t match_len = 0; // Unused in this path.
const char in_anchored = 0;
const char in_catchup = 0;
const char from_mpv = 0;
const char skip_mpv_catchup = 1;
const u8 flags = ROSE_PROG_FLAG_SKIP_MPV_CATCHUP;
hwlmcb_rv_t rv =
roseRunProgram(rose, scratch, program, som, offset, match_len,
in_anchored, in_catchup, from_mpv, skip_mpv_catchup);
roseRunProgram(rose, scratch, program, som, offset, match_len, flags);
if (rv == HWLM_TERMINATE_MATCHING) {
return MO_HALT_MATCHING;
}

View File

@ -29,17 +29,20 @@
#ifndef ROSE_MATCH_H
#define ROSE_MATCH_H
#include "hwlm/hwlm.h"
#include "catchup.h"
#include "runtime.h"
#include "scratch.h"
#include "report.h"
#include "rose_common.h"
#include "rose_internal.h"
#include "ue2common.h"
#include "hwlm/hwlm.h"
#include "nfa/nfa_api.h"
#include "nfa/nfa_api_queue.h"
#include "nfa/nfa_api_util.h"
#include "som/som_runtime.h"
#include "util/bitutils.h"
#include "util/exhaust.h"
#include "util/fatbit.h"
#include "util/multibit.h"
@ -295,4 +298,85 @@ int roseHasInFlightMatches(const struct RoseEngine *t, char *state,
return 0;
}
static rose_inline
hwlmcb_rv_t roseHaltIfExhausted(const struct RoseEngine *t,
struct hs_scratch *scratch) {
struct core_info *ci = &scratch->core_info;
if (isAllExhausted(t, ci->exhaustionVector)) {
ci->status |= STATUS_EXHAUSTED;
scratch->tctxt.groups = 0;
DEBUG_PRINTF("all exhausted, termination requested\n");
return HWLM_TERMINATE_MATCHING;
}
return HWLM_CONTINUE_MATCHING;
}
static really_inline
hwlmcb_rv_t ensureQueueFlushed_i(const struct RoseEngine *t,
struct hs_scratch *scratch, u32 qi, s64a loc,
char is_mpv, char in_catchup) {
struct RoseContext *tctxt = &scratch->tctxt;
u8 *aa = getActiveLeafArray(t, scratch->core_info.state);
struct fatbit *activeQueues = scratch->aqa;
u32 aaCount = t->activeArrayCount;
u32 qCount = t->queueCount;
struct mq *q = &scratch->queues[qi];
DEBUG_PRINTF("qcl %lld, loc: %lld, min (non mpv) match offset: %llu\n",
q_cur_loc(q), loc, tctxt->minNonMpvMatchOffset);
if (q_cur_loc(q) == loc) {
/* too many tops enqueued at the one spot; need to flatten this queue.
* We can use the full catchups as it will short circuit as we are
* already at this location. It also saves waking everybody up */
pushQueueNoMerge(q, MQE_END, loc);
nfaQueueExec(q->nfa, q, loc);
q->cur = q->end = 0;
pushQueueAt(q, 0, MQE_START, loc);
} else if (!in_catchup) {
if (is_mpv) {
tctxt->next_mpv_offset = 0; /* force us to catch the mpv */
if (loc + scratch->core_info.buf_offset
<= tctxt->minNonMpvMatchOffset) {
DEBUG_PRINTF("flushing chained\n");
if (roseCatchUpMPV(t, loc, scratch) ==
HWLM_TERMINATE_MATCHING) {
return HWLM_TERMINATE_MATCHING;
}
goto done_queue_empty;
}
}
if (roseCatchUpTo(t, scratch, loc + scratch->core_info.buf_offset) ==
HWLM_TERMINATE_MATCHING) {
return HWLM_TERMINATE_MATCHING;
}
} else {
/* we must be a chained nfa */
assert(is_mpv);
DEBUG_PRINTF("flushing chained\n");
tctxt->next_mpv_offset = 0; /* force us to catch the mpv */
if (roseCatchUpMPV(t, loc, scratch) == HWLM_TERMINATE_MATCHING) {
return HWLM_TERMINATE_MATCHING;
}
}
done_queue_empty:
if (!mmbit_set(aa, aaCount, qi)) {
initQueue(q, qi, t, scratch);
nfaQueueInitState(q->nfa, q);
pushQueueAt(q, 0, MQE_START, loc);
fatbit_set(activeQueues, qCount, qi);
}
assert(!isQueueFull(q));
return roseHaltIfExhausted(t, scratch);
}
static rose_inline
hwlmcb_rv_t ensureQueueFlushed(const struct RoseEngine *t,
struct hs_scratch *scratch, u32 qi, s64a loc) {
return ensureQueueFlushed_i(t, scratch, qi, loc, 0, 0);
}
#endif

1421
src/rose/program_runtime.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -705,13 +705,10 @@ void roseStreamEodExec(const struct RoseEngine *t, u64a offset,
const u64a som = 0;
const size_t match_len = 0;
const char in_anchored = 0;
const char in_catchup = 0;
const char from_mpv = 0;
const char skip_mpv_catchup = 1;
const u8 flags = ROSE_PROG_FLAG_SKIP_MPV_CATCHUP;
// Note: we ignore the result, as this is the last thing to ever happen on
// a scan.
roseRunProgram(t, scratch, t->eodProgramOffset, som, offset, match_len,
in_anchored, in_catchup, from_mpv, skip_mpv_catchup);
flags);
}