]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
rose: minor clean up of catchup
authorAlex Coyte <a.coyte@intel.com>
Sun, 23 Apr 2017 23:51:58 +0000 (09:51 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 30 May 2017 03:58:32 +0000 (13:58 +1000)
- anchored dfa do not mean that catchup is required
- remove needsCatchup from rose bytecode as catchup is based on interpreter

src/rose/program_runtime.h
src/rose/rose_build_bytecode.cpp
src/rose/rose_build_dump.cpp
src/rose/rose_internal.h

index 10a87c8b27249b78a6779cc013fd4e175bba5def..090913ae6fa341c34a294cd3d08a2e92c103d898 100644 (file)
@@ -484,7 +484,6 @@ static rose_inline
 hwlmcb_rv_t roseReport(const struct RoseEngine *t, struct hs_scratch *scratch,
                        u64a end, ReportID onmatch, s32 offset_adjust,
                        u32 ekey) {
-    assert(!t->needsCatchup || end == scratch->tctxt.minMatchOffset);
     DEBUG_PRINTF("firing callback onmatch=%u, end=%llu\n", onmatch, end);
     updateLastMatchOffset(&scratch->tctxt, end);
 
@@ -518,13 +517,11 @@ hwlmcb_rv_t roseCatchUpAndHandleChainMatch(const struct RoseEngine *t,
 }
 
 static rose_inline
-void roseHandleSom(UNUSED const struct RoseEngine *t,
-                   struct hs_scratch *scratch, const struct som_operation *sr,
+void roseHandleSom(struct hs_scratch *scratch, const struct som_operation *sr,
                    u64a end) {
     DEBUG_PRINTF("end=%llu, minMatchOffset=%llu\n", end,
                  scratch->tctxt.minMatchOffset);
 
-    assert(!t->needsCatchup || end == scratch->tctxt.minMatchOffset);
     updateLastMatchOffset(&scratch->tctxt, end);
     handleSomInternal(scratch, sr, end);
 }
@@ -533,7 +530,6 @@ static rose_inline
 hwlmcb_rv_t roseReportSom(const struct RoseEngine *t,
                           struct hs_scratch *scratch, u64a start, u64a end,
                           ReportID onmatch, s32 offset_adjust, u32 ekey) {
-    assert(!t->needsCatchup || end == scratch->tctxt.minMatchOffset);
     DEBUG_PRINTF("firing som callback onmatch=%u, start=%llu, end=%llu\n",
                  onmatch, start, end);
     updateLastMatchOffset(&scratch->tctxt, end);
@@ -553,13 +549,11 @@ hwlmcb_rv_t roseReportSom(const struct RoseEngine *t,
 }
 
 static rose_inline
-void roseHandleSomSom(UNUSED const struct RoseEngine *t,
-                      struct hs_scratch *scratch,
+void roseHandleSomSom(struct hs_scratch *scratch,
                       const struct som_operation *sr, u64a start, u64a end) {
     DEBUG_PRINTF("start=%llu, end=%llu, minMatchOffset=%llu\n", start, end,
                  scratch->tctxt.minMatchOffset);
 
-    assert(!t->needsCatchup || end == scratch->tctxt.minMatchOffset);
     updateLastMatchOffset(&scratch->tctxt, end);
     setSomFromSomAware(scratch, sr, start, end);
 }
@@ -2211,14 +2205,14 @@ hwlmcb_rv_t roseRunProgram_i(const struct RoseEngine *t,
 
             PROGRAM_CASE(REPORT_SOM_INT) {
                 updateSeqPoint(tctxt, end, from_mpv);
-                roseHandleSom(t, scratch, &ri->som, end);
+                roseHandleSom(scratch, &ri->som, end);
                 work_done = 1;
             }
             PROGRAM_NEXT_INSTRUCTION
 
             PROGRAM_CASE(REPORT_SOM_AWARE) {
                 updateSeqPoint(tctxt, end, from_mpv);
-                roseHandleSomSom(t, scratch, &ri->som, som, end);
+                roseHandleSomSom(scratch, &ri->som, som, end);
                 work_done = 1;
             }
             PROGRAM_NEXT_INSTRUCTION
index bd7481ab1310e8bc0662d5a6de77e0edaa7f5ce5..a53cc53411f51b5cda599c2c11495bfae1c412a0 100644 (file)
@@ -231,9 +231,9 @@ struct build_context : noncopyable {
      * RoseEngine. */
     RoseEngineBlob engine_blob;
 
-    /** \brief True if reports need CATCH_UP instructions, to catch up anchored
-     * matches, suffixes, outfixes etc. */
-    bool needs_catchup = false;
+    /** \brief True if reports need CATCH_UP instructions to catch up suffixes,
+     * outfixes etc. */
+    bool needs_catchup;
 
     /** \brief True if this Rose engine has an MPV engine. */
     bool needs_mpv_catchup = false;
@@ -327,38 +327,39 @@ u32 countRosePrefixes(const vector<LeftNfaInfo> &roses) {
 }
 
 /**
- * \brief True if this Rose engine needs to run a catch up whenever a report is
- * generated.
+ * \brief True if this Rose engine needs to run a catch up whenever a literal
+ * report is generated.
  *
  * Catch up is necessary if there are output-exposed engines (suffixes,
- * outfixes) or an anchored table (anchored literals, acyclic DFAs).
+ * outfixes).
  */
 static
-bool needsCatchup(const RoseBuildImpl &build,
-                  const vector<raw_dfa> &anchored_dfas) {
+bool needsCatchup(const RoseBuildImpl &build) {
+    /* Note: we could be more selective about when we need to generate catch up
+     * instructions rather than just a boolean yes/no - for instance, if we know
+     * that a role can only match before the point that an outfix/suffix could
+     * match, we do not strictly need a catchup instruction.
+     *
+     * However, this would add a certain amount of complexity to the
+     * catchup logic and would likely have limited applicability - how many
+     * reporting roles have a fixed max offset and how much time is spent on
+     * catchup for these cases?
+     */
+
     if (!build.outfixes.empty()) {
+        /* TODO: check that they have non-eod reports */
         DEBUG_PRINTF("has outfixes\n");
         return true;
     }
-    if (!anchored_dfas.empty()) {
-        DEBUG_PRINTF("has anchored dfas\n");
-        return true;
-    }
 
     const RoseGraph &g = build.g;
 
     for (auto v : vertices_range(g)) {
-        if (build.root == v) {
-            continue;
-        }
-        if (build.anchored_root == v) {
-            continue;
-        }
         if (g[v].suffix) {
+            /* TODO: check that they have non-eod reports */
             DEBUG_PRINTF("vertex %zu has suffix\n", g[v].index);
             return true;
         }
-
     }
 
     DEBUG_PRINTF("no need for catch-up on report\n");
@@ -4794,7 +4795,7 @@ static
 RoseProgram makeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
                                ProgramBuild &prog_build, u32 lit_id,
                                const vector<RoseEdge> &lit_edges,
-                               bool is_anchored_program) {
+                               bool is_anchored_replay_program) {
     const auto &g = build.g;
 
     DEBUG_PRINTF("lit id=%u, %zu lit edges\n", lit_id, lit_edges.size());
@@ -4844,7 +4845,7 @@ RoseProgram makeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
     makeGroupSquashInstruction(build, lit_id, root_block);
 
     // Literal may be anchored and need to be recorded.
-    if (!is_anchored_program) {
+    if (!is_anchored_replay_program) {
         makeRecordAnchoredInstruction(build, prog_build, lit_id, root_block);
     }
 
@@ -4863,7 +4864,7 @@ static
 RoseProgram makeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
                                ProgramBuild &prog_build, u32 lit_id,
                                const map<u32, vector<RoseEdge>> &lit_edge_map,
-                               bool is_anchored_program) {
+                               bool is_anchored_replay_program) {
     const vector<RoseEdge> no_edges;
 
     DEBUG_PRINTF("lit_id=%u\n", lit_id);
@@ -4875,7 +4876,7 @@ RoseProgram makeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
     }
 
     return makeLiteralProgram(build, bc, prog_build, lit_id, *edges_ptr,
-                              is_anchored_program);
+                              is_anchored_replay_program);
 }
 
 /**
@@ -5726,7 +5727,7 @@ bytecode_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
     u32 floatingMinLiteralMatchOffset
         = findMinFloatingLiteralMatch(*this, anchored_dfas);
     bc.longLitLengthThreshold = longLitLengthThreshold;
-    bc.needs_catchup = needsCatchup(*this, anchored_dfas);
+    bc.needs_catchup = needsCatchup(*this);
     recordResources(bc.resources, *this, fragments);
     if (!anchored_dfas.empty()) {
         bc.resources.has_anchored = true;
@@ -5891,8 +5892,6 @@ bytecode_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
     proto.somLocationCount = ssm.numSomSlots();
     proto.somLocationFatbitSize = fatbit_size(proto.somLocationCount);
 
-    proto.needsCatchup = bc.needs_catchup ? 1 : 0;
-
     proto.runtimeImpl = pickRuntimeImpl(*this, bc.resources,
                                         proto.outfixEndQueue);
     proto.mpvTriggeredByLeaf = anyEndfixMpvTriggers(*this);
index a52830b031a47c326b04554b9565c7a870ab6868..73ed830ea0e2c91124894b2415c378101d5628ee 100644 (file)
@@ -2112,7 +2112,6 @@ void roseDumpStructRaw(const RoseEngine *t, FILE *f) {
     DUMP_U8(t, canExhaust);
     DUMP_U8(t, hasSom);
     DUMP_U8(t, somHorizon);
-    DUMP_U8(t, needsCatchup);
     DUMP_U32(t, mode);
     DUMP_U32(t, historyRequired);
     DUMP_U32(t, ekeyCount);
index 06a9b0692b2eb63c1a0bf85d2d161b6366b98acc..777e7234c2ffa21773bf5c752ef3b0754c62f5d6 100644 (file)
@@ -304,7 +304,6 @@ struct RoseEngine {
     u8  hasSom; /**< has at least one pattern which tracks SOM. */
     u8  somHorizon; /**< width in bytes of SOM offset storage (governed by
                         SOM precision) */
-    u8 needsCatchup; /** catch up needs to be run on every report. */
     u32 mode; /**< scanning mode, one of HS_MODE_{BLOCK,STREAM,VECTORED} */
     u32 historyRequired; /**< max amount of history required for streaming */
     u32 ekeyCount; /**< number of exhaustion keys */