source: icGREP/icgrep-devel/icgrep/re/re_memoizer.hpp

Last change on this file was 5630, checked in by nmedfort, 2 months ago

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 size: 678 bytes
Line 
1#ifndef RE_MEMOIZER_H
2#define RE_MEMOIZER_H
3
4#include <re/re_name.h>
5#include <set>
6
7namespace re {
8
9struct MemoizerComparator {
10    bool operator() (const RE * lh, const RE * rh) const;
11};
12
13struct Memoizer : public std::set<RE *, MemoizerComparator> {
14
15    RE * memoize(RE * const re) {
16        return *(insert(re).first);
17    }
18
19    Name * memoize(Name * const name) {
20        return llvm::cast<Name>(memoize(llvm::cast<RE>(name)));
21    }
22
23    Name * memoize(CC * const cc) {
24        auto f = find(cc);
25        if (f != end()) {
26            return llvm::cast<Name>(*f);
27        } else {
28            return memoize(makeName(cc));
29        }
30    }
31};
32
33}
34
35#endif // RE_MEMOIZER_H
Note: See TracBrowser for help on using the repository browser.