]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
add checkViolet and switch SOM path accross to use violet
authorAlex Coyte <a.coyte@intel.com>
Thu, 5 Jan 2017 00:37:34 +0000 (11:37 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 04:44:49 +0000 (14:44 +1000)
src/nfagraph/ng.cpp
src/nfagraph/ng_som.cpp
src/nfagraph/ng_violet.cpp
src/nfagraph/ng_violet.h

index caf631f7e2ed3f96c5fde52a08fcaa37dd3e1a9c..a4f86fee10073ad02962c11b8630ecf2bab09526 100644 (file)
@@ -533,16 +533,13 @@ bool NG::addHolder(NGHolder &w) {
         return true;
     }
 
-    if (splitOffRose(*rose, w, prefilter, rm, cc)) {
+    if (doViolet(*rose, w, prefilter, false, rm, cc)) {
         return true;
     }
     if (splitOffPuffs(*rose, rm, w, prefilter, cc)) {
         return true;
     }
-    if (splitOffRose(*rose, w, prefilter, rm, cc)) {
-        return true;
-    }
-    if (finalChanceRose(*rose, w, prefilter, rm, cc)) {
+    if (doViolet(*rose, w, prefilter, true, rm, cc)) {
         return true;
     }
 
index f6ba0fa7d21cacc675a8ad4c2f9bc2b773175cfa..8d3d75a37f5a8b1d1598dfa7254bbca49abff008 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
 #include "ng_redundancy.h"
 #include "ng_region.h"
 #include "ng_reports.h"
-#include "ng_rose.h"
 #include "ng_som.h"
 #include "ng_som_add_redundancy.h"
 #include "ng_som_util.h"
 #include "ng_split.h"
 #include "ng_util.h"
+#include "ng_violet.h"
 #include "ng_width.h"
 #include "grey.h"
 #include "ue2common.h"
@@ -2073,7 +2073,7 @@ sombe_rv doHaigLitSom(NG &ng, NGHolder &g, const NGWrapper &w, u32 comp_id,
     const u32 numSomLocsBefore = ssm.numSomSlots(); /* for rollback */
     u32 som_loc = ssm.getPrivateSomSlot();
 
-    if (!checkRose(rm, g, false, cc) && !isImplementableNFA(g, &rm, cc)) {
+    if (!checkViolet(rm, g, false, cc) && !isImplementableNFA(g, &rm, cc)) {
         // This is an optimisation: if we can't build a Haig from a portion of
         // the graph, then we won't be able to manage it as an outfix either
         // when we fall back.
index 3c0aee15e34b422daacb0c6d05fbbba5e5f0ff9f..28ad9549c02c95249d3a3840469f67ab6c09467e 100644 (file)
@@ -2867,25 +2867,24 @@ bool ensureImplementable(RoseBuild &rose, RoseInGraph &vg, bool allow_changes,
     return true;
 }
 
-bool doViolet(RoseBuild &rose, const NGHolder &h, bool prefilter,
-              bool last_chance, const ReportManager &rm,
-              const CompileContext &cc) {
+static
+RoseInGraph doInitialVioletTransform(const NGHolder &h,
+                                     const CompileContext &cc) {
     assert(!can_never_match(h));
 
+    RoseInGraph vg = populateTrivialGraph(h);
+
     if (!cc.grey.allowViolet) {
-        return false;
+        return vg;
     }
 
     DEBUG_PRINTF("hello world\n");
 
-    RoseInGraph vg = populateTrivialGraph(h);
-
     /* Step 1: avoid outfixes as we always have to run them. */
     avoidOutfixes(vg, cc);
 
     if (num_vertices(vg) <= 2) {
-        /* only have an outfix; leave for ng_rose for now */
-        return false;
+        return vg; /* unable to transform pattern */
     }
 
     removeRedundantPrefixes(vg);
@@ -2923,6 +2922,17 @@ bool doViolet(RoseBuild &rose, const NGHolder &h, bool prefilter,
     renumber_vertices(vg);
     calcVertexOffsets(vg);
 
+    return vg;
+}
+
+bool doViolet(RoseBuild &rose, const NGHolder &h, bool prefilter,
+              bool last_chance, const ReportManager &rm,
+              const CompileContext &cc) {
+    auto vg = doInitialVioletTransform(h, cc);
+    if (num_vertices(vg) <= 2) {
+        return false;
+    }
+
     /* Step 5: avoid unimplementable, or overly large engines if possible */
     if (!ensureImplementable(rose, vg, last_chance, last_chance, rm, cc)) {
         return false;
@@ -2935,4 +2945,16 @@ bool doViolet(RoseBuild &rose, const NGHolder &h, bool prefilter,
     return rv;
 }
 
+bool checkViolet(const ReportManager &rm, const NGHolder &h, bool prefilter,
+                 const CompileContext &cc) {
+    auto vg = doInitialVioletTransform(h, cc);
+    if (num_vertices(vg) <= 2) {
+        return false;
+    }
+
+    bool rv = roseCheckRose(vg, prefilter, rm, cc);
+    DEBUG_PRINTF("violet: %s\n", rv ? "success" : "fail");
+    return rv;
+}
+
 }
index b6ecd0284fdf5b56d8e0c11a553e638f5b7589a9..3fe57dbfaa18812814fee0e0431357169b552c99 100644 (file)
@@ -53,6 +53,13 @@ bool doViolet(RoseBuild &rose, const NGHolder &h, bool prefilter,
 bool ensureImplementable(RoseBuild &rose, RoseInGraph &vg, bool allow_changes,
                          bool final_chance, const ReportManager &rm,
                          const CompileContext &cc);
+
+/** \brief True if the pattern in \a h is consumable by Rose/Violet. This
+ * function may be conservative (return false even if supported) for
+ * efficiency. */
+bool checkViolet(const ReportManager &rm, const NGHolder &h, bool prefilter,
+                 const CompileContext &cc);
+
 } // namespace ue2
 
 #endif