source: icGREP/icgrep-devel/icgrep/re/re_simplifier.cpp @ 6173

Last change on this file since 6173 was 6173, checked in by nmedfort, 7 months ago

Added RE_Inspector.

Migrated RE passes to RE_Transformer.

Incorporated Memoizer functionality into RE_Transformer/Inspector.

Removed Memoizer.

Bug fix for unicode_set.

File size: 1.6 KB
Line 
1#include "re_simplifier.h"
2#include <re/re_name.h>
3#include <re/re_alt.h>
4#include <re/re_seq.h>
5#include <re/re_rep.h>
6#include <re/re_range.h>
7#include <re/re_diff.h>
8#include <re/re_intersect.h>
9#include <re/re_assertion.h>
10#include <re/re_toolchain.h>
11#include <boost/container/flat_set.hpp>
12
13using namespace llvm;
14
15namespace re {
16
17using Set = boost::container::flat_set<RE *>;
18using List = std::vector<RE *>;
19
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);
30                }
31            }  else {
32                set.insert(item);
33            }
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;
45            }
46            list.push_back(item);
47        }
48        return makeSeq(list.begin(), list.end());
49    }
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
58};
59
60RE * RE_Simplifier::simplify(RE * re) {
61    PassContainer pc;
62    return pc.transformRE(re);
63}
64
65}
Note: See TracBrowser for help on using the repository browser.