]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
ng_literal_decorated: pre-check for narrow reach
authorJustin Viiret <justin.viiret@intel.com>
Wed, 31 May 2017 00:27:24 +0000 (10:27 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 21 Aug 2017 01:10:11 +0000 (11:10 +1000)
src/nfagraph/ng_literal_decorated.cpp
src/nfagraph/ng_util.cpp
src/nfagraph/ng_util.h
src/nfagraph/ng_violet.cpp

index 89c01a6ce3332c36584c435c703bbe1c3eb5c169..3ba810f9555f375672dd870666c538f0415e4a19 100644 (file)
@@ -210,6 +210,11 @@ bool handleDecoratedLiterals(RoseBuild &rose, const NGHolder &g,
         return false;
     }
 
+    if (!hasNarrowReachVertex(g)) {
+        DEBUG_PRINTF("no narrow reach vertices\n");
+        return false;
+    }
+
     if (hasLargeDegreeVertex(g)) {
         DEBUG_PRINTF("large degree\n");
         return false;
index 0776fa0442d531a1e1247815223b08daa9fffdd3..c0ad61990ad4e27f5fe0b557974579bb39779950 100644 (file)
@@ -257,6 +257,12 @@ bool hasBigCycles(const NGHolder &g) {
     return false;
 }
 
+bool hasNarrowReachVertex(const NGHolder &g, size_t max_reach_count) {
+    return any_of_in(vertices_range(g), [&](NFAVertex v) {
+        return !is_special(v, g) && g[v].char_reach.count() < max_reach_count;
+    });
+}
+
 bool can_never_match(const NGHolder &g) {
     assert(edge(g.accept, g.acceptEod, g).second);
     if (in_degree(g.accept, g) == 0 && in_degree(g.acceptEod, g) == 1) {
index 1d3a6f325ea83e2f4f04f2d517a291df919ba951..4c529a83f577d8a7c0e45c36981db89c1266e7ee 100644 (file)
@@ -233,6 +233,12 @@ bool hasReachableCycle(const NGHolder &g, NFAVertex src);
 /** True if g has any cycles which are not self-loops. */
 bool hasBigCycles(const NGHolder &g);
 
+/**
+ * \brief True if g has at least one non-special vertex with reach smaller than
+ * max_reach_count. The default of 200 is pretty conservative.
+ */
+bool hasNarrowReachVertex(const NGHolder &g, size_t max_reach_count = 200);
+
 /** Returns the set of all vertices that appear in any of the graph's cycles. */
 std::set<NFAVertex> findVerticesInCycles(const NGHolder &g);
 
index c9460b93c66286a5da1a38faa6f72d4cf5e5cc8a..2e1171ab3b5835bf529da872ca6fd9a4ede0cd97 100644 (file)
@@ -2954,9 +2954,7 @@ RoseInGraph doInitialVioletTransform(const NGHolder &h, bool last_chance,
 
     /* Avoid running the Violet analysis at all on graphs with no vertices with
      * small reach, since we will not be able to extract any literals. */
-    if (all_of_in(vertices_range(h), [&](NFAVertex v) {
-            return is_special(v, h) || h[v].char_reach.count() >= 200;
-        })) {
+    if (!hasNarrowReachVertex(h)) {
         DEBUG_PRINTF("fail, no vertices with small reach\n");
         return vg;
     }