Changeset 5604


Ignore:
Timestamp:
Aug 7, 2017, 11:40:06 AM (2 months ago)
Author:
xuedongx
Message:

update re_analysis for unit bounded repetition and local language

Location:
icGREP/icgrep-devel/icgrep/re
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_analysis.cpp

    r5559 r5604  
    194194}
    195195
    196 
    197 }
     196//If a regular expression contains unit and not byteLength bounded repetition type, we select a different pipeline to utilize the log2 technique.
     197bool unitBoundedRep(const RE * re) {
     198    if (const Alt * alt = dyn_cast<Alt>(re)) {
     199        for (const RE * re : *alt) {
     200            if (unitBoundedRep(re)) {
     201                return true;
     202            }
     203        }
     204        return false;
     205    } else if (const Seq * seq = dyn_cast<Seq>(re)) {
     206        for (const RE * re : *seq) {
     207            if (unitBoundedRep(re)) {
     208                return true;
     209            }
     210        }
     211        return false;
     212    } else if (const Rep * rep = dyn_cast<Rep>(re)) {
     213        if (rep->getLB() == 0 && rep->getUB() == Rep::UNBOUNDED_REP) {
     214            return false;
     215        } else {
     216            return (!isByteLength(rep->getRE()) && isUnicodeUnitLength(rep->getRE()));
     217        }
     218    } else if (const Diff * diff = dyn_cast<Diff>(re)) {
     219        return unitBoundedRep(diff->getLH()) || unitBoundedRep(diff->getRH());
     220    } else if (const Intersect * e = dyn_cast<Intersect>(re)) {
     221        return unitBoundedRep(e->getLH()) || unitBoundedRep(e->getRH());
     222    } else if (const Name * n = dyn_cast<Name>(re)) {
     223        if (n->getType() == Name::Type::Capture || n->getType() == Name::Type::Reference) {
     224            return unitBoundedRep(n->getDefinition());
     225        }
     226        return false;
     227    }
     228    return false; // otherwise
     229 
     230}
     231
     232//Cases that not include bounded repetition, assertion, start and end type can suit for local language compile pipeline.
     233bool isTypeForLocal(const RE * re) {
     234    if (const Alt * alt = dyn_cast<Alt>(re)) {
     235        for (const RE * re : *alt) {
     236            if (!isTypeForLocal(re)) {
     237                return false;
     238            }
     239        }
     240        return true;
     241    } else if (const Seq * seq = dyn_cast<Seq>(re)) {
     242    for (const RE * re : *seq) {
     243        if (!isTypeForLocal(re)) {
     244            return false;
     245        }
     246    }
     247        return true;
     248    } else if (const Rep * rep = dyn_cast<Rep>(re)) {
     249        if (rep->getLB() != 0 || rep->getUB() != Rep::UNBOUNDED_REP) {
     250            return false;
     251        }
     252        return true;
     253    } else if (const Diff * diff = dyn_cast<Diff>(re)) {
     254        return isTypeForLocal(diff->getLH()) && isTypeForLocal(diff->getRH());
     255    } else if (const Intersect * e = dyn_cast<Intersect>(re)) {
     256        return isTypeForLocal(e->getLH()) && isTypeForLocal(e->getRH());
     257    } else if (isa<Start>(re) || isa<End>(re) || isa<Assertion>(re)) {
     258        return false;
     259    }
     260    return true; // otherwise
     261}
     262
     263}
  • icGREP/icgrep-devel/icgrep/re/re_analysis.h

    r5267 r5604  
    1515int minMatchLength(RE * re);
    1616
     17bool unitBoundedRep(const RE * re);
     18
     19bool isTypeForLocal(const RE * re);
     20
    1721}
    1822
Note: See TracChangeset for help on using the changeset viewer.