Ignore:
Timestamp:
Oct 16, 2018, 2:29:44 PM (7 months ago)
Author:
nmedfort
Message:

Added RE_Inspector.

Migrated RE passes to RE_Transformer.

Incorporated Memoizer functionality into RE_Transformer/Inspector.

Removed Memoizer.

Bug fix for unicode_set.

File:
1 edited

Legend:

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

    r5763 r6173  
    88#include <re/re_intersect.h>
    99#include <re/re_assertion.h>
    10 #include <re/re_memoizer.hpp>
     10#include <re/re_toolchain.h>
    1111#include <boost/container/flat_set.hpp>
    1212
     
    1818using List = std::vector<RE *>;
    1919
    20 struct PassContainer {
    21     RE * simplify(RE * re) {
    22         if (Alt * alt = dyn_cast<Alt>(re)) {
    23             Set set;
    24             set.reserve(alt->size());
    25             for (RE * item : *alt) {
    26                 item = simplify(item);
    27                 if (LLVM_UNLIKELY(isa<Alt>(item) && cast<Alt>(item)->empty())) {
    28                     continue;
     20struct PassContainer final : public RE_Transformer {
     21
     22    RE * transformAlt(Alt * alt) override {
     23        Set set;
     24        set.reserve(alt->size());
     25        for (RE * item : *alt) {
     26            item = transform(item);
     27            if (LLVM_UNLIKELY(isa<Alt>(item))) {
     28                for (RE * innerAlt : *cast<Alt>(item)) {
     29                    set.insert(innerAlt);
    2930                }
     31            }  else {
    3032                set.insert(item);
    3133            }
    32             re = makeAlt(set.begin(), set.end());
    33         } else if (Seq * seq = dyn_cast<Seq>(re)) {
    34             List list;
    35             list.reserve(seq->size());
    36             for (RE * item : *seq) {
    37                 item = simplify(item);
    38                 if (LLVM_UNLIKELY(isa<Seq>(item) && cast<Seq>(item)->empty())) {
    39                     continue;
    40                 }
    41                 list.push_back(item);
     34        }
     35        return makeAlt(set.begin(), set.end());
     36    }
     37
     38    RE * transformSeq(Seq * seq) override {
     39        List list;
     40        list.reserve(seq->size());
     41        for (RE * item : *seq) {
     42            item = transform(item);
     43            if (LLVM_UNLIKELY(isa<Vector>(item) && cast<Vector>(item)->empty())) {
     44                continue;
    4245            }
    43             re = makeSeq(list.begin(), list.end());
    44         } else if (Assertion * a = dyn_cast<Assertion>(re)) {
    45             re = makeAssertion(simplify(a->getAsserted()), a->getKind(), a->getSense());
    46         } else if (Rep * rep = dyn_cast<Rep>(re)) {
    47             RE * expr = simplify(rep->getRE());
    48             re = makeRep(expr, rep->getLB(), rep->getUB());
    49         } else if (Diff * diff = dyn_cast<Diff>(re)) {
    50             re = makeDiff(simplify(diff->getLH()), simplify(diff->getRH()));
    51         } else if (Range * rg = dyn_cast<Range>(re)) {
    52             re = makeRange(simplify(rg->getLo()), simplify(rg->getHi()));
    53         } else if (Intersect * e = dyn_cast<Intersect>(re)) {
    54             re = makeIntersect(simplify(e->getLH()), simplify(e->getRH()));
     46            list.push_back(item);
    5547        }
    56         return mMemoizer.memoize(re);
     48        return makeSeq(list.begin(), list.end());
    5749    }
    58 private:
    59     Memoizer mMemoizer;
     50
     51    RE * transformName(Name * nm) override {
     52        nm->setDefinition(transform(nm->getDefinition()));
     53        return nm;
     54    }
     55
     56    PassContainer() : RE_Transformer("Simplifier", NameTransformationMode::TransformDefinition) { }
     57
    6058};
    6159
    6260RE * RE_Simplifier::simplify(RE * re) {
    6361    PassContainer pc;
    64     return pc.simplify(re);
     62    return pc.transformRE(re);
    6563}
    6664
Note: See TracChangeset for help on using the changeset viewer.