]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
rose: only write out report programs if in use
authorJustin Viiret <justin.viiret@intel.com>
Thu, 14 Jul 2016 06:17:06 +0000 (16:17 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 10 Aug 2016 05:05:53 +0000 (15:05 +1000)
These programs are only used by output-exposed engines.

src/rose/rose_build_bytecode.cpp
src/rose/rose_internal.h
src/smallwrite/smallwrite_build.cpp
src/smallwrite/smallwrite_build.h

index c0d8d0a7aff6e53ce119ac0441f84783ea399938..6eb42d4cfd26da06b59796af733ef8e5e3436670 100644 (file)
@@ -4761,27 +4761,57 @@ pair<u32, u32> buildLiteralPrograms(RoseBuildImpl &build, build_context &bc) {
     return {litProgramsOffset, delayRebuildProgramsOffset};
 }
 
+/**
+ * \brief Returns all reports used by output-exposed engines, for which we need
+ * to generate programs.
+ */
+static
+set<ReportID> findEngineReports(const RoseBuildImpl &build) {
+    set<ReportID> reports;
+
+    // The small write engine uses these engine report programs.
+    insert(&reports, build.smwr.all_reports());
+
+    for (const auto &outfix : build.outfixes) {
+        insert(&reports, all_reports(outfix));
+    }
+
+    const auto &g = build.g;
+    for (auto v : vertices_range(g)) {
+        if (g[v].suffix) {
+            insert(&reports, all_reports(g[v].suffix));
+        }
+    }
+
+    DEBUG_PRINTF("%zu engine reports (of %zu)\n", reports.size(),
+                 build.rm.numReports());
+    return reports;
+}
+
 static
-u32 buildReportPrograms(RoseBuildImpl &build, build_context &bc) {
-    const auto &rm = build.rm;
-    const u32 numReports = verify_u32(rm.numReports());
-    vector<u32> programs(numReports);
+pair<u32, u32> buildReportPrograms(RoseBuildImpl &build, build_context &bc) {
+    const auto reports = findEngineReports(build);
+    vector<u32> programs;
+    programs.reserve(reports.size());
 
     vector<RoseInstruction> program;
-    for (ReportID id = 0; id < numReports; id++) {
+    for (ReportID id : reports) {
         program.clear();
         const bool has_som = false;
         makeCatchupMpv(build, bc, id, program);
         makeReport(build, id, has_som, program);
         program = flattenProgram({program});
         applyFinalSpecialisation(program);
-        programs[id] = writeProgram(bc, program);
-        build.rm.setProgramOffset(id, programs[id]);
+        u32 offset = writeProgram(bc, program);
+        programs.push_back(offset);
+        build.rm.setProgramOffset(id, offset);
         DEBUG_PRINTF("program for report %u @ %u (%zu instructions)\n", id,
                      programs.back(), program.size());
     }
 
-    return add_to_engine_blob(bc, begin(programs), end(programs));
+    u32 offset = add_to_engine_blob(bc, begin(programs), end(programs));
+    u32 count = verify_u32(programs.size());
+    return {offset, count};
 }
 
 static
@@ -5174,7 +5204,10 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
 
     auto boundary_out = makeBoundaryPrograms(*this, bc, boundary, dboundary);
 
-    u32 reportProgramOffset = buildReportPrograms(*this, bc);
+    u32 reportProgramOffset;
+    u32 reportProgramCount;
+    tie(reportProgramOffset, reportProgramCount) =
+        buildReportPrograms(*this, bc);
 
     // Build NFAs
     set<u32> no_retrigger_queues;
@@ -5394,7 +5427,7 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
     engine->litProgramOffset = litProgramOffset;
     engine->litDelayRebuildProgramOffset = litDelayRebuildProgramOffset;
     engine->reportProgramOffset = reportProgramOffset;
-    engine->reportProgramCount = verify_u32(rm.reports().size());
+    engine->reportProgramCount = reportProgramCount;
     engine->runtimeImpl = pickRuntimeImpl(*this, bc, outfixEndQueue);
     engine->mpvTriggeredByLeaf = anyEndfixMpvTriggers(*this);
 
index 2b646af0fe569bc2e672578effc91ec9fce50038..51913984f24dea12e50119cb136807e96760e598 100644 (file)
@@ -347,10 +347,15 @@ struct RoseEngine {
      * literals. */
     u32 litDelayRebuildProgramOffset;
 
-    /** \brief Offset of u32 array of program offsets for internal reports. */
+    /**
+     * \brief Offset of u32 array of program offsets for reports used by
+     * output-exposed engines.
+     */
     u32 reportProgramOffset;
 
-    /** \brief Number of programs for internal reports. */
+    /**
+     * \brief Number of programs for reports used by output-exposed engines.
+     */
     u32 reportProgramCount;
 
     /**
index 7fb5444020319953a3fec76dd7cd382a604e33a0..1cffe514e4ba9e74686e52fb358a9b3d8350bc9a 100644 (file)
@@ -74,6 +74,8 @@ public:
     void add(const NGWrapper &w) override;
     void add(const ue2_literal &literal, ReportID r) override;
 
+    set<ReportID> all_reports() const override;
+
     bool determiniseLiterals();
 
     const ReportManager &rm;
@@ -413,6 +415,20 @@ SmallWriteBuildImpl::build(u32 roseQuality) {
     return smwr;
 }
 
+set<ReportID> SmallWriteBuildImpl::all_reports() const {
+    set<ReportID> reports;
+    if (poisoned) {
+        return reports;
+    }
+    if (rdfa) {
+        insert(&reports, ::ue2::all_reports(*rdfa));
+    }
+    for (const auto &cand : cand_literals) {
+        reports.insert(cand.second);
+    }
+    return reports;
+}
+
 size_t smwrSize(const SmallWriteEngine *smwr) {
     assert(smwr);
     return smwr->size;
index 59a8528ad179ff64c4cc6f22eb9251cc0bbac6fa..84c6df3a2f523563b2f8fbfb2fd4a0d1a7cf6bb9 100644 (file)
@@ -38,6 +38,8 @@
 #include "ue2common.h"
 #include "util/alloc.h"
 
+#include <set>
+
 #include <boost/core/noncopyable.hpp>
 
 struct SmallWriteEngine;
@@ -61,6 +63,8 @@ public:
 
     virtual void add(const NGWrapper &w) = 0;
     virtual void add(const ue2_literal &literal, ReportID r) = 0;
+
+    virtual std::set<ReportID> all_reports() const = 0;
 };
 
 // Construct a usable SmallWrite builder.