ng_literal_decorated: pre-check for narrow reach

This commit is contained in:
Justin Viiret 2017-05-31 10:27:24 +10:00 committed by Matthew Barr
parent 5a7d5958d1
commit 5837f68b9a
4 changed files with 18 additions and 3 deletions

View File

@ -210,6 +210,11 @@ bool handleDecoratedLiterals(RoseBuild &rose, const NGHolder &g,
return false; return false;
} }
if (!hasNarrowReachVertex(g)) {
DEBUG_PRINTF("no narrow reach vertices\n");
return false;
}
if (hasLargeDegreeVertex(g)) { if (hasLargeDegreeVertex(g)) {
DEBUG_PRINTF("large degree\n"); DEBUG_PRINTF("large degree\n");
return false; return false;

View File

@ -257,6 +257,12 @@ bool hasBigCycles(const NGHolder &g) {
return false; return false;
} }
bool hasNarrowReachVertex(const NGHolder &g, size_t max_reach_count) {
return any_of_in(vertices_range(g), [&](NFAVertex v) {
return !is_special(v, g) && g[v].char_reach.count() < max_reach_count;
});
}
bool can_never_match(const NGHolder &g) { bool can_never_match(const NGHolder &g) {
assert(edge(g.accept, g.acceptEod, g).second); assert(edge(g.accept, g.acceptEod, g).second);
if (in_degree(g.accept, g) == 0 && in_degree(g.acceptEod, g) == 1) { if (in_degree(g.accept, g) == 0 && in_degree(g.acceptEod, g) == 1) {

View File

@ -233,6 +233,12 @@ bool hasReachableCycle(const NGHolder &g, NFAVertex src);
/** True if g has any cycles which are not self-loops. */ /** True if g has any cycles which are not self-loops. */
bool hasBigCycles(const NGHolder &g); bool hasBigCycles(const NGHolder &g);
/**
* \brief True if g has at least one non-special vertex with reach smaller than
* max_reach_count. The default of 200 is pretty conservative.
*/
bool hasNarrowReachVertex(const NGHolder &g, size_t max_reach_count = 200);
/** Returns the set of all vertices that appear in any of the graph's cycles. */ /** Returns the set of all vertices that appear in any of the graph's cycles. */
std::set<NFAVertex> findVerticesInCycles(const NGHolder &g); std::set<NFAVertex> findVerticesInCycles(const NGHolder &g);

View File

@ -2954,9 +2954,7 @@ RoseInGraph doInitialVioletTransform(const NGHolder &h, bool last_chance,
/* Avoid running the Violet analysis at all on graphs with no vertices with /* Avoid running the Violet analysis at all on graphs with no vertices with
* small reach, since we will not be able to extract any literals. */ * small reach, since we will not be able to extract any literals. */
if (all_of_in(vertices_range(h), [&](NFAVertex v) { if (!hasNarrowReachVertex(h)) {
return is_special(v, h) || h[v].char_reach.count() >= 200;
})) {
DEBUG_PRINTF("fail, no vertices with small reach\n"); DEBUG_PRINTF("fail, no vertices with small reach\n");
return vg; return vg;
} }