]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
rose: reduce anchored program dep on final_id
authorJustin Viiret <justin.viiret@intel.com>
Mon, 13 Feb 2017 23:19:25 +0000 (10:19 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 05:04:30 +0000 (15:04 +1000)
We only need to build anchored programs for cases where a
RECORD_ANCHORED instruction has been generated, and we can key those
directly rather than using final_id.

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

index 7172f6aadf2ca017be6b35ef1edda8ff2ce88da2..d67c307ffaf0b0954d6835742ab3fafde1ac0a08 100644 (file)
@@ -103,7 +103,7 @@ void rosePushDelayedMatch(const struct RoseEngine *t,
 
 static rose_inline
 void recordAnchoredLiteralMatch(const struct RoseEngine *t,
-                                struct hs_scratch *scratch, u32 literal_id,
+                                struct hs_scratch *scratch, u32 anch_id,
                                 u64a end) {
     assert(end);
 
@@ -113,7 +113,7 @@ void recordAnchoredLiteralMatch(const struct RoseEngine *t,
 
     struct fatbit **anchoredLiteralRows = getAnchoredLiteralLog(scratch);
 
-    DEBUG_PRINTF("record %u @ %llu\n", literal_id, end);
+    DEBUG_PRINTF("record %u (of %u) @ %llu\n", anch_id, t->anchored_count, end);
 
     if (!bf64_set(&scratch->al_log_sum, end - 1)) {
         // first time, clear row
@@ -121,11 +121,8 @@ void recordAnchoredLiteralMatch(const struct RoseEngine *t,
         fatbit_clear(anchoredLiteralRows[end - 1]);
     }
 
-    u32 rel_idx = literal_id - t->anchored_base_id;
-    DEBUG_PRINTF("record %u @ %llu index %u/%u\n", literal_id, end, rel_idx,
-                 t->anchored_count);
-    assert(rel_idx < t->anchored_count);
-    fatbit_set(anchoredLiteralRows[end - 1], t->anchored_count, rel_idx);
+    assert(anch_id < t->anchored_count);
+    fatbit_set(anchoredLiteralRows[end - 1], t->anchored_count, anch_id);
 }
 
 static rose_inline
index da0195e92917f85ad86a8db6bd089b6a4133296f..c050e6839265df89c7c9c013131f010edff9d4a6 100644 (file)
@@ -246,6 +246,9 @@ struct build_context : boost::noncopyable {
 
     /** \brief Mapping from final ID to the set of literals it is used for. */
     map<u32, flat_set<u32>> final_id_to_literal;
+
+    /** \brief Mapping from final ID to anchored program index. */
+    map<u32, u32> anchored_programs;
 };
 
 /** \brief subengine info including built engine and
@@ -4269,7 +4272,14 @@ void makeRecordAnchoredInstruction(const RoseBuildImpl &build,
         return;
     }
 
-    program.add_before_end(make_unique<RoseInstrRecordAnchored>(final_id));
+    auto it = bc.anchored_programs.find(final_id);
+    if (it == bc.anchored_programs.end()) {
+        u32 anch_id = verify_u32(bc.anchored_programs.size());
+        it = bc.anchored_programs.emplace(final_id, anch_id).first;
+        DEBUG_PRINTF("added anch_id=%u for final_id %u\n", anch_id, final_id);
+    }
+    u32 anch_id = it->second;
+    program.add_before_end(make_unique<RoseInstrRecordAnchored>(anch_id));
 }
 
 static
@@ -4757,11 +4767,14 @@ u32 buildAnchoredPrograms(RoseBuildImpl &build, build_context &bc) {
     auto lit_edge_map = findEdgesByLiteral(build);
 
     vector<u32> programs;
+    programs.resize(bc.anchored_programs.size(), ROSE_INVALID_PROG_OFFSET);
 
-    for (u32 final_id = build.anchored_base_id;
-         final_id < build.delay_base_id; final_id++) {
+    for (const auto &m : bc.anchored_programs) {
+        u32 final_id = m.first;
+        u32 anch_id = m.second;
         u32 offset = writeLiteralProgram(build, bc, {final_id}, lit_edge_map);
-        programs.push_back(offset);
+        DEBUG_PRINTF("final_id %u -> anch prog at %u\n", final_id, offset);
+        programs[anch_id] = offset;
     }
 
     DEBUG_PRINTF("%zu anchored programs\n", programs.size());
@@ -5704,7 +5717,7 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
     engine->delay_fatbit_size = fatbit_size(engine->delay_count);
     engine->delay_base_id = delay_base_id;
     engine->anchored_base_id = anchored_base_id;
-    engine->anchored_count = delay_base_id - anchored_base_id;
+    engine->anchored_count = bc.anchored_programs.size();
     engine->anchored_fatbit_size = fatbit_size(engine->anchored_count);
 
     engine->rosePrefixCount = rosePrefixCount;