Ignore:
Timestamp:
Sep 7, 2017, 4:56:56 PM (22 months ago)
Author:
nmedfort
Message:

Partial check-in for avoidance of compiling Pablo/LLVM code to determine the Kernel struct type when using a cached object. Inactive RE alternation minimization check in.

File:
1 edited

Legend:

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

    r5493 r5630  
    11#include "re_simplifier.h"
    22#include <re/re_name.h>
    3 #include <re/re_any.h>
    4 #include <re/re_start.h>
    5 #include <re/re_end.h>
    63#include <re/re_alt.h>
    7 #include <re/re_cc.h>
    84#include <re/re_seq.h>
    95#include <re/re_rep.h>
     
    117#include <re/re_intersect.h>
    128#include <re/re_assertion.h>
    13 #include <re/re_analysis.h>
    14 #include <algorithm>
    15 #include <memory>
    16 #include <queue>
     9#include <re/re_memoizer.hpp>
     10#include <boost/container/flat_set.hpp>
    1711
    1812using namespace llvm;
     
    2014namespace re {
    2115
     16struct PassContainer {
     17    RE * simplify(RE * re) {
     18        if (Alt * alt = dyn_cast<Alt>(re)) {
     19            boost::container::flat_set<RE *> list;
     20            list.reserve(alt->size());
     21            for (RE * item : *alt) {
     22                item = simplify(item);
     23                if (LLVM_UNLIKELY(isa<Vector>(item) && cast<Vector>(item)->empty())) {
     24                    continue;
     25                }
     26                list.insert(item);
     27            }
     28            re = makeAlt(list.begin(), list.end());
     29        } else if (Seq * seq = dyn_cast<Seq>(re)) {
     30            std::vector<RE *> list;
     31            list.reserve(seq->size());
     32            for (RE * item : *seq) {
     33                item = simplify(item);
     34                if (LLVM_UNLIKELY(isa<Vector>(item) && cast<Vector>(item)->empty())) {
     35                    continue;
     36                }
     37                list.push_back(item);
     38            }
     39            re = makeSeq(list.begin(), list.end());
     40        } else if (Assertion * a = dyn_cast<Assertion>(re)) {
     41            re = makeAssertion(simplify(a->getAsserted()), a->getKind(), a->getSense());
     42        } else if (Rep * rep = dyn_cast<Rep>(re)) {
     43            RE * expr = simplify(rep->getRE());
     44            re = makeRep(expr, rep->getLB(), rep->getUB());
     45        } else if (Diff * diff = dyn_cast<Diff>(re)) {
     46            re = makeDiff(simplify(diff->getLH()), simplify(diff->getRH()));
     47        } else if (Intersect * e = dyn_cast<Intersect>(re)) {
     48            re = makeIntersect(simplify(e->getLH()), simplify(e->getRH()));
     49        }
     50        return mMemoizer.memoize(re);
     51    }
     52private:
     53    Memoizer mMemoizer;
     54};
     55
    2256RE * RE_Simplifier::simplify(RE * re) {
    23     if (Alt * alt = dyn_cast<Alt>(re)) {
    24         std::vector<RE *> list;
    25         list.reserve(alt->size());
    26         for (RE * re : *alt) {
    27             list.push_back(simplify(re));
    28         }
    29         re = makeAlt(list.begin(), list.end());
    30     } else if (Seq * seq = dyn_cast<Seq>(re)) {
    31         std::vector<RE *> list;
    32         list.reserve(seq->size());
    33         for (RE * re : *seq) {
    34             list.push_back(simplify(re));
    35         }
    36         re = makeSeq(list.begin(), list.end());
    37     } else if (Assertion * a = dyn_cast<Assertion>(re)) {
    38         re = makeAssertion(simplify(a->getAsserted()), a->getKind(), a->getSense());
    39     } else if (Rep * rep = dyn_cast<Rep>(re)) {
    40         RE * expr = simplify(rep->getRE());
    41         re = makeRep(expr, rep->getLB(), rep->getUB());
    42     } else if (Diff * diff = dyn_cast<Diff>(re)) {
    43         re = makeDiff(simplify(diff->getLH()), simplify(diff->getRH()));
    44     } else if (Intersect * e = dyn_cast<Intersect>(re)) {
    45         re = makeIntersect(simplify(e->getLH()), simplify(e->getRH()));
    46     }
    47     return re;
     57    PassContainer pc;
     58    return pc.simplify(re);
    4859}
    4960
Note: See TracChangeset for help on using the changeset viewer.