diff --git a/src/nfagraph/ng.cpp b/src/nfagraph/ng.cpp index caf631f7..a4f86fee 100644 --- a/src/nfagraph/ng.cpp +++ b/src/nfagraph/ng.cpp @@ -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; } diff --git a/src/nfagraph/ng_som.cpp b/src/nfagraph/ng_som.cpp index f6ba0fa7..8d3d75a3 100644 --- a/src/nfagraph/ng_som.cpp +++ b/src/nfagraph/ng_som.cpp @@ -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: @@ -40,12 +40,12 @@ #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. diff --git a/src/nfagraph/ng_violet.cpp b/src/nfagraph/ng_violet.cpp index 3c0aee15..28ad9549 100644 --- a/src/nfagraph/ng_violet.cpp +++ b/src/nfagraph/ng_violet.cpp @@ -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; +} + } diff --git a/src/nfagraph/ng_violet.h b/src/nfagraph/ng_violet.h index b6ecd028..3fe57dbf 100644 --- a/src/nfagraph/ng_violet.h +++ b/src/nfagraph/ng_violet.h @@ -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