]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
hwlm: use bytecode_ptr for HWLM structures
authorJustin Viiret <justin.viiret@intel.com>
Mon, 3 Apr 2017 03:56:49 +0000 (13:56 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 05:19:36 +0000 (15:19 +1000)
src/hwlm/hwlm_build.cpp
src/hwlm/hwlm_build.h
src/rose/rose_build_bytecode.cpp
src/rose/rose_build_matchers.cpp
src/rose/rose_build_matchers.h

index cd98feb468c501735b87c1b597f15396f30ccac6..824ac3fdea24db0c35e1b1487594964c6d834712 100644 (file)
@@ -97,9 +97,9 @@ bool isNoodleable(const vector<hwlmLiteral> &lits,
     return true;
 }
 
-aligned_unique_ptr<HWLM> hwlmBuild(const vector<hwlmLiteral> &lits,
-                                   bool make_small, const CompileContext &cc,
-                                   UNUSED hwlm_group_t expected_groups) {
+bytecode_ptr<HWLM> hwlmBuild(const vector<hwlmLiteral> &lits, bool make_small,
+                             const CompileContext &cc,
+                             UNUSED hwlm_group_t expected_groups) {
     assert(!lits.empty());
     dumpLits(lits);
 
@@ -151,7 +151,7 @@ aligned_unique_ptr<HWLM> hwlmBuild(const vector<hwlmLiteral> &lits,
         engType = HWLM_ENGINE_FDR;
         auto fdr = fdrBuildTable(lits, make_small, cc.target_info, cc.grey);
         if (fdr) {
-            engSize = fdrSize(fdr.get());
+            engSize = fdr.size();
         }
         eng = move(fdr);
     }
@@ -165,7 +165,7 @@ aligned_unique_ptr<HWLM> hwlmBuild(const vector<hwlmLiteral> &lits,
         throw ResourceLimitError();
     }
 
-    auto h = aligned_zmalloc_unique<HWLM>(ROUNDUP_CL(sizeof(HWLM)) + engSize);
+    auto h = make_bytecode_ptr<HWLM>(ROUNDUP_CL(sizeof(HWLM)) + engSize, 64);
 
     h->type = engType;
     memcpy(HWLM_DATA(h.get()), eng.get(), engSize);
index 5dd7dbc9065f32bf2b471263b6e56a537e415c76..f2691496eee4dc8e0e0e67f8e7fe325ecb5d86b9 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "hwlm.h"
 #include "ue2common.h"
-#include "util/alloc.h"
+#include "util/bytecode_ptr.h"
 
 #include <memory>
 #include <vector>
@@ -60,10 +60,9 @@ struct hwlmLiteral;
  * may result in a nullptr return value, or a std::bad_alloc exception being
  * thrown.
  */
-aligned_unique_ptr<HWLM>
-hwlmBuild(const std::vector<hwlmLiteral> &lits, bool make_small,
-          const CompileContext &cc,
-          hwlm_group_t expected_groups = HWLM_ALL_GROUPS);
+bytecode_ptr<HWLM> hwlmBuild(const std::vector<hwlmLiteral> &lits,
+                             bool make_small, const CompileContext &cc,
+                             hwlm_group_t expected_groups = HWLM_ALL_GROUPS);
 
 /**
  * Returns an estimate of the number of repeated characters on the end of a
index 4447646a385d7935b5fb51103443d7d54b42bdf5..f7c8cf06c9eadbb4410e35541ecfcb4665b77506 100644 (file)
@@ -5832,35 +5832,30 @@ bytecode_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
 
     // Build floating HWLM matcher.
     rose_group fgroups = 0;
-    size_t fsize = 0;
     auto ftable = buildFloatingMatcher(*this, fragments,
-                                       bc.longLitLengthThreshold,
-                                       &fgroups, &fsize, &historyRequired);
+                        bc.longLitLengthThreshold, &fgroups, &historyRequired);
     if (ftable) {
-        proto.fmatcherOffset = bc.engine_blob.add(ftable.get(), fsize, 64);
+        proto.fmatcherOffset = bc.engine_blob.add(ftable);
         bc.resources.has_floating = true;
     }
 
     // Build delay rebuild HWLM matcher.
-    size_t drsize = 0;
     auto drtable = buildDelayRebuildMatcher(*this, fragments,
-                                            bc.longLitLengthThreshold, &drsize);
+                                            bc.longLitLengthThreshold);
     if (drtable) {
-        proto.drmatcherOffset = bc.engine_blob.add(drtable.get(), drsize, 64);
+        proto.drmatcherOffset = bc.engine_blob.add(drtable);
     }
 
     // Build EOD-anchored HWLM matcher.
-    size_t esize = 0;
-    auto etable = buildEodAnchoredMatcher(*this, fragments, &esize);
+    auto etable = buildEodAnchoredMatcher(*this, fragments);
     if (etable) {
-        proto.ematcherOffset = bc.engine_blob.add(etable.get(), esize, 64);
+        proto.ematcherOffset = bc.engine_blob.add(etable);
     }
 
     // Build small-block HWLM matcher.
-    size_t sbsize = 0;
-    auto sbtable = buildSmallBlockMatcher(*this, fragments, &sbsize);
+    auto sbtable = buildSmallBlockMatcher(*this, fragments);
     if (sbtable) {
-        proto.sbmatcherOffset = bc.engine_blob.add(sbtable.get(), sbsize, 64);
+        proto.sbmatcherOffset = bc.engine_blob.add(sbtable);
     }
 
     proto.activeArrayCount = proto.leftfixBeginQueue;
index 7f1467d742bb40b800423dcd3133e9f8855e33a9..64a1c9199ff7bdc803cb666a948426dd0770fc70 100644 (file)
@@ -805,12 +805,11 @@ void buildAccel(const RoseBuildImpl &build, const MatcherProto &mp,
     buildForwardAccel(&hwlm, mp.accel_lits, build.getInitialGroups());
 }
 
-aligned_unique_ptr<HWLM>
-buildFloatingMatcher(const RoseBuildImpl &build,
-                     const vector<LitFragment> &fragments,
-                     size_t longLitLengthThreshold, rose_group *fgroups,
-                     size_t *fsize, size_t *historyRequired) {
-    *fsize = 0;
+bytecode_ptr<HWLM> buildFloatingMatcher(const RoseBuildImpl &build,
+                                        const vector<LitFragment> &fragments,
+                                        size_t longLitLengthThreshold,
+                                        rose_group *fgroups,
+                                        size_t *historyRequired) {
     *fgroups = 0;
 
     auto mp = makeMatcherProto(build, fragments, ROSE_FLOATING, false,
@@ -838,18 +837,14 @@ buildFloatingMatcher(const RoseBuildImpl &build,
         *historyRequired = max(*historyRequired, mp.history_required);
     }
 
-    *fsize = hwlmSize(hwlm.get());
-    assert(*fsize);
-    DEBUG_PRINTF("built floating literal table size %zu bytes\n", *fsize);
+    DEBUG_PRINTF("built floating literal table size %zu bytes\n", hwlm.size());
     return hwlm;
 }
 
-aligned_unique_ptr<HWLM> buildDelayRebuildMatcher(const RoseBuildImpl &build,
-                                       const vector<LitFragment> &fragments,
-                                                  size_t longLitLengthThreshold,
-                                                  size_t *drsize) {
-    *drsize = 0;
-
+bytecode_ptr<HWLM>
+buildDelayRebuildMatcher(const RoseBuildImpl &build,
+                         const vector<LitFragment> &fragments,
+                         size_t longLitLengthThreshold) {
     if (!build.cc.streaming) {
         DEBUG_PRINTF("not streaming\n");
         return nullptr;
@@ -870,17 +865,13 @@ aligned_unique_ptr<HWLM> buildDelayRebuildMatcher(const RoseBuildImpl &build,
 
     buildAccel(build, mp, *hwlm);
 
-    *drsize = hwlmSize(hwlm.get());
-    assert(*drsize);
-    DEBUG_PRINTF("built delay rebuild table size %zu bytes\n", *drsize);
+    DEBUG_PRINTF("built delay rebuild table size %zu bytes\n", hwlm.size());
     return hwlm;
 }
 
-aligned_unique_ptr<HWLM>
+bytecode_ptr<HWLM>
 buildSmallBlockMatcher(const RoseBuildImpl &build,
-                       const vector<LitFragment> &fragments, size_t *sbsize) {
-    *sbsize = 0;
-
+                       const vector<LitFragment> &fragments) {
     if (build.cc.streaming) {
         DEBUG_PRINTF("streaming mode\n");
         return nullptr;
@@ -932,17 +923,14 @@ buildSmallBlockMatcher(const RoseBuildImpl &build,
 
     buildAccel(build, mp, *hwlm);
 
-    *sbsize = hwlmSize(hwlm.get());
-    assert(*sbsize);
-    DEBUG_PRINTF("built small block literal table size %zu bytes\n", *sbsize);
+    DEBUG_PRINTF("built small block literal table size %zu bytes\n",
+                 hwlm.size());
     return hwlm;
 }
 
-aligned_unique_ptr<HWLM>
+bytecode_ptr<HWLM>
 buildEodAnchoredMatcher(const RoseBuildImpl &build,
-                        const vector<LitFragment> &fragments, size_t *esize) {
-    *esize = 0;
-
+                        const vector<LitFragment> &fragments) {
     auto mp = makeMatcherProto(build, fragments, ROSE_EOD_ANCHORED, false,
                                build.ematcher_region_size);
 
@@ -962,9 +950,8 @@ buildEodAnchoredMatcher(const RoseBuildImpl &build,
 
     buildAccel(build, mp, *hwlm);
 
-    *esize = hwlmSize(hwlm.get());
-    assert(*esize);
-    DEBUG_PRINTF("built eod-anchored literal table size %zu bytes\n", *esize);
+    DEBUG_PRINTF("built eod-anchored literal table size %zu bytes\n",
+                 hwlm.size());
     return hwlm;
 }
 
index 494a3aeb9740a859fc75e183252d2957c5a640cb..2b1afc8c6bd934df5a3da49fe55dd140cb0ac4a5 100644 (file)
@@ -35,6 +35,7 @@
 #define ROSE_BUILD_MATCHERS_H
 
 #include "rose_build_impl.h"
+#include "util/bytecode_ptr.h"
 
 #include <vector>
 
@@ -57,25 +58,24 @@ struct LitFragment {
     u32 delay_program_offset = ROSE_INVALID_PROG_OFFSET;
 };
 
-aligned_unique_ptr<HWLM> buildFloatingMatcher(const RoseBuildImpl &build,
-                                  const std::vector<LitFragment> &fragments,
-                                              size_t longLitLengthThreshold,
-                                              rose_group *fgroups,
-                                              size_t *fsize,
-                                              size_t *historyRequired);
+bytecode_ptr<HWLM>
+buildFloatingMatcher(const RoseBuildImpl &build,
+                     const std::vector<LitFragment> &fragments,
+                     size_t longLitLengthThreshold, rose_group *fgroups,
+                     size_t *historyRequired);
 
-aligned_unique_ptr<HWLM> buildDelayRebuildMatcher(const RoseBuildImpl &build,
-                                  const std::vector<LitFragment> &fragments,
-                                                  size_t longLitLengthThreshold,
-                                                  size_t *drsize);
+bytecode_ptr<HWLM>
+buildDelayRebuildMatcher(const RoseBuildImpl &build,
+                         const std::vector<LitFragment> &fragments,
+                         size_t longLitLengthThreshold);
 
-aligned_unique_ptr<HWLM> buildSmallBlockMatcher(const RoseBuildImpl &build,
-                                  const std::vector<LitFragment> &fragments,
-                                                size_t *sbsize);
+bytecode_ptr<HWLM>
+buildSmallBlockMatcher(const RoseBuildImpl &build,
+                       const std::vector<LitFragment> &fragments);
 
-aligned_unique_ptr<HWLM> buildEodAnchoredMatcher(const RoseBuildImpl &build,
-                                  const std::vector<LitFragment> &fragments,
-                                                 size_t *esize);
+bytecode_ptr<HWLM>
+buildEodAnchoredMatcher(const RoseBuildImpl &build,
+                        const std::vector<LitFragment> &fragments);
 
 void findMoreLiteralMasks(RoseBuildImpl &build);