From 2a492273b536c83bd9bb265a96a3102a76a30ac5 Mon Sep 17 00:00:00 2001 From: Alex Coyte Date: Thu, 10 Aug 2017 13:43:20 +1000 Subject: [PATCH] remove !LBR constraints from merge passes we have either converted candidates to castles already or we have converted them back in the hope of merging them with other holders --- src/nfagraph/ng_lbr.cpp | 20 -------------------- src/nfagraph/ng_lbr.h | 3 --- src/rose/rose_build_merge.cpp | 33 ++++++--------------------------- unit/internal/lbr.cpp | 2 -- 4 files changed, 6 insertions(+), 52 deletions(-) diff --git a/src/nfagraph/ng_lbr.cpp b/src/nfagraph/ng_lbr.cpp index 9bf16efe..d8ba503c 100644 --- a/src/nfagraph/ng_lbr.cpp +++ b/src/nfagraph/ng_lbr.cpp @@ -346,24 +346,4 @@ bytecode_ptr constructLBR(const NGHolder &g, return constructLBR(proto, triggers, cc, rm); } -/** \brief True if graph \p g could be turned into an LBR engine. */ -bool isLBR(const NGHolder &g, const Grey &grey) { - if (!grey.allowLbr) { - return false; - } - - PureRepeat repeat; - if (!isPureRepeat(g, repeat)) { - DEBUG_PRINTF("not pure bounded repeat\n"); - return false; - } - - if (repeat.reports.size() != 1) { - DEBUG_PRINTF("too many reports\n"); - return false; - } - - return true; -} - } // namespace ue2 diff --git a/src/nfagraph/ng_lbr.h b/src/nfagraph/ng_lbr.h index 1eec9653..c181dbb9 100644 --- a/src/nfagraph/ng_lbr.h +++ b/src/nfagraph/ng_lbr.h @@ -66,9 +66,6 @@ constructLBR(const CastleProto &proto, const std::vector> &triggers, const CompileContext &cc, const ReportManager &rm); -/** \brief True if graph \p g could be turned into an LBR engine. */ -bool isLBR(const NGHolder &g, const Grey &grey); - } // namespace ue2 #endif // NG_LBR_H diff --git a/src/rose/rose_build_merge.cpp b/src/rose/rose_build_merge.cpp index 0d73c101..fb7b3a1f 100644 --- a/src/rose/rose_build_merge.cpp +++ b/src/rose/rose_build_merge.cpp @@ -101,10 +101,6 @@ static const size_t DFA_CHUNK_SIZE_MAX = 200; /** \brief Max DFA states in a merged DFA. */ static const size_t DFA_MERGE_MAX_STATES = 8000; -/** \brief An LBR must have at least this many vertices to be protected from - * merging with other graphs. */ -static const size_t LARGE_LBR_MIN_VERTICES = 32; - /** \brief In block mode, merge two prefixes even if they don't have identical * literal sets if they have fewer than this many states and the merged graph * is also small. */ @@ -122,14 +118,6 @@ size_t small_rose_threshold(const CompileContext &cc) { : SMALL_ROSE_THRESHOLD_BLOCK; } -static -bool isLargeLBR(const NGHolder &g, const Grey &grey) { - if (num_vertices(g) < LARGE_LBR_MIN_VERTICES) { - return false; - } - return isLBR(g, grey); -} - namespace { struct DupeLeafKey { explicit DupeLeafKey(const RoseVertexProps &litv) @@ -1889,6 +1877,12 @@ void dedupeLeftfixesVariableLag(RoseBuildImpl &tbi) { continue; } + if (leftfix.graph()) { + /* we should not have merged yet */ + assert(!is_triggered(*leftfix.graph()) + || onlyOneTop(*leftfix.graph())); + } + roseGrouping[DedupeLeftKey(tbi, v)].insert(leftfix, v); } @@ -2275,11 +2269,6 @@ void mergeSmallLeftfixes(RoseBuildImpl &tbi) { continue; } - // Don't merge cases that will become LBRs or haigs. - if (isLargeLBR(h, tbi.cc.grey)) { - continue; - } - // Small roses only. if (num_vertices(h) > small_rose_threshold(tbi.cc)) { continue; @@ -2497,11 +2486,6 @@ void mergeAcyclicSuffixes(RoseBuildImpl &tbi) { continue; } - if (isLargeLBR(*h, tbi.cc.grey)) { - DEBUG_PRINTF("not considering LBR suffix for merge\n"); - continue; - } - suffixes.insert(g[v].suffix, v); } @@ -2564,11 +2548,6 @@ void mergeSmallSuffixes(RoseBuildImpl &tbi) { continue; } - if (isLargeLBR(*h, tbi.cc.grey)) { - DEBUG_PRINTF("not considering LBR suffix for merge\n"); - continue; - } - suffixes.insert(g[v].suffix, v); } diff --git a/unit/internal/lbr.cpp b/unit/internal/lbr.cpp index d32f7e8f..2c585ae5 100644 --- a/unit/internal/lbr.cpp +++ b/unit/internal/lbr.cpp @@ -101,8 +101,6 @@ protected: ASSERT_TRUE(g != nullptr); clearReports(*g); - ASSERT_TRUE(isLBR(*g, grey)); - rm.setProgramOffset(0, MATCH_REPORT); /* LBR triggered by dot */