]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Prevent trying to build smallwrite engine for large cases
authorAlex Coyte <a.coyte@intel.com>
Mon, 30 May 2016 04:00:31 +0000 (14:00 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Fri, 8 Jul 2016 00:46:46 +0000 (10:46 +1000)
src/grey.cpp
src/grey.h
src/hs.cpp
src/nfagraph/ng.cpp
src/nfagraph/ng.h
src/smallwrite/smallwrite_build.cpp
src/smallwrite/smallwrite_build.h

index 69dab627f381f956608d477a54802cedef2dbf68..e2022e74163e14672f3d9174db14cf21401f405f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -126,6 +126,8 @@ Grey::Grey(void) :
                                                 // are given to rose &co
                    smallWriteLargestBufferBad(35),
                    limitSmallWriteOutfixSize(1048576), // 1 MB
+                   smallWriteMaxPatterns(10000),
+                   smallWriteMaxLiterals(10000),
                    dumpFlags(0),
                    limitPatternCount(8000000), // 8M patterns
                    limitPatternLength(16000),  // 16K bytes
@@ -273,6 +275,8 @@ void applyGreyOverrides(Grey *g, const string &s) {
         G_UPDATE(smallWriteLargestBuffer);
         G_UPDATE(smallWriteLargestBufferBad);
         G_UPDATE(limitSmallWriteOutfixSize);
+        G_UPDATE(smallWriteMaxPatterns);
+        G_UPDATE(smallWriteMaxLiterals);
         G_UPDATE(limitPatternCount);
         G_UPDATE(limitPatternLength);
         G_UPDATE(limitGraphVertices);
index a226105200f240ee36e4d6fc9c737b709ccf5ae7..8ac9e6b180430519243e1245aab3d1b366f27cdc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -143,6 +143,8 @@ struct Grey {
     u32 smallWriteLargestBuffer;  // largest buffer that can be small write
     u32 smallWriteLargestBufferBad;// largest buffer that can be small write
     u32 limitSmallWriteOutfixSize; //!< max total size of outfix DFAs
+    u32 smallWriteMaxPatterns; // only try small writes if fewer patterns
+    u32 smallWriteMaxLiterals; // only try small writes if fewer literals
 
     enum DumpFlags {
         DUMP_NONE       = 0,
index 3680e79eb8b9ffb76db7f6c1d6263bb3fc8f78fd..07f6d2c1e502f616b24a75c69d0bc45ac907a259 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -219,7 +219,7 @@ hs_compile_multi_int(const char *const *expressions, const unsigned *flags,
                                     : get_current_target();
 
     CompileContext cc(isStreaming, isVectored, target_info, g);
-    NG ng(cc, somPrecision);
+    NG ng(cc, elements, somPrecision);
 
     try {
         for (unsigned int i = 0; i < elements; i++) {
index b4b34d741d59cfae7dda40884ab049e9fd238cf6..5d4f1b97729b28482597c66a071dcdd216a6d3aa 100644 (file)
@@ -75,14 +75,15 @@ using namespace std;
 
 namespace ue2 {
 
-NG::NG(const CompileContext &in_cc, unsigned in_somPrecision)
+NG::NG(const CompileContext &in_cc, size_t num_patterns,
+       unsigned in_somPrecision)
     : maxSomRevHistoryAvailable(in_cc.grey.somMaxRevNfaLength),
       minWidth(depth::infinity()),
       rm(in_cc.grey),
       ssm(in_somPrecision),
       cc(in_cc),
       rose(makeRoseBuilder(rm, ssm, cc, boundary)),
-      smwr(makeSmallWriteBuilder(rm, cc)) {
+      smwr(makeSmallWriteBuilder(num_patterns, rm, cc)) {
 }
 
 NG::~NG() {
index 52353da927a552bd6e36f6dc1039190298965c78..95936fcc03d76a90fa36b0c14f08259ca8aecdad 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -87,7 +87,8 @@ class SmallWriteBuild;
 
 class NG : boost::noncopyable {
 public:
-    NG(const CompileContext &in_cc, unsigned in_somPrecision);
+    NG(const CompileContext &in_cc, size_t num_patterns,
+       unsigned in_somPrecision);
     ~NG();
 
     /** \brief Consumes a pattern, returns false or throws a CompileError
index 792a3d5b30cd848da73507dceed4a42764c73a13..7fb5444020319953a3fec76dd7cd382a604e33a0 100644 (file)
@@ -65,7 +65,8 @@ namespace { // unnamed
 // Concrete impl class
 class SmallWriteBuildImpl : public SmallWriteBuild {
 public:
-    SmallWriteBuildImpl(const ReportManager &rm, const CompileContext &cc);
+    SmallWriteBuildImpl(size_t num_patterns, const ReportManager &rm,
+                        const CompileContext &cc);
 
     // Construct a runtime implementation.
     aligned_unique_ptr<SmallWriteEngine> build(u32 roseQuality) override;
@@ -87,11 +88,14 @@ public:
 
 SmallWriteBuild::~SmallWriteBuild() { }
 
-SmallWriteBuildImpl::SmallWriteBuildImpl(const ReportManager &rm_in,
+SmallWriteBuildImpl::SmallWriteBuildImpl(size_t num_patterns,
+                                         const ReportManager &rm_in,
                                          const CompileContext &cc_in)
     : rm(rm_in), cc(cc_in),
       /* small write is block mode only */
-      poisoned(!cc.grey.allowSmallWrite || cc.streaming) {
+      poisoned(!cc.grey.allowSmallWrite
+               || cc.streaming
+               || num_patterns > cc.grey.smallWriteMaxPatterns) {
 }
 
 void SmallWriteBuildImpl::add(const NGWrapper &w) {
@@ -163,6 +167,10 @@ void SmallWriteBuildImpl::add(const ue2_literal &literal, ReportID r) {
     }
 
     cand_literals.push_back(make_pair(literal, r));
+
+    if (cand_literals.size() > cc.grey.smallWriteMaxLiterals) {
+        poisoned = true;
+    }
 }
 
 static
@@ -181,6 +189,7 @@ void lit_to_graph(NGHolder *h, const ue2_literal &literal, ReportID r) {
 bool SmallWriteBuildImpl::determiniseLiterals() {
     DEBUG_PRINTF("handling literals\n");
     assert(!poisoned);
+    assert(cand_literals.size() <= cc.grey.smallWriteMaxLiterals);
 
     if (cand_literals.empty()) {
         return true; /* nothing to do */
@@ -352,9 +361,10 @@ aligned_unique_ptr<NFA> prepEngine(raw_dfa &rdfa, u32 roseQuality,
 }
 
 // SmallWriteBuild factory
-unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(const ReportManager &rm,
+unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(size_t num_patterns,
+                                                  const ReportManager &rm,
                                                   const CompileContext &cc) {
-    return ue2::make_unique<SmallWriteBuildImpl>(rm, cc);
+    return ue2::make_unique<SmallWriteBuildImpl>(num_patterns, rm, cc);
 }
 
 aligned_unique_ptr<SmallWriteEngine>
index 9c3de9d387c46db0853fca7574c2f708286a577b..59a8528ad179ff64c4cc6f22eb9251cc0bbac6fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -64,7 +64,8 @@ public:
 };
 
 // Construct a usable SmallWrite builder.
-std::unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(const ReportManager &rm,
+std::unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(size_t num_patterns,
+                                                       const ReportManager &rm,
                                                        const CompileContext &cc);
 
 size_t smwrSize(const SmallWriteEngine *t);