source: icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_bddminimization.h @ 4880

Last change on this file since 4880 was 4880, checked in by nmedfort, 4 years ago

More work on n-ary operations.

File size: 1.5 KB
Line 
1#ifndef PABLO_BDDMINIMIZATION_H
2#define PABLO_BDDMINIMIZATION_H
3
4#include <boost/container/flat_map.hpp>
5#include <vector>
6
7typedef int BDD;
8
9namespace pablo {
10
11class PabloAST;
12class PabloBlock;
13class PabloFunction;
14class Statement;
15
16class BDDMinimizationPass {
17
18    using CharacterizationMap = boost::container::flat_map<const PabloAST *, BDD>;
19
20    struct SubsitutionMap {
21        SubsitutionMap(SubsitutionMap * parent = nullptr) : mParent(parent) {}
22
23        PabloAST * get(const BDD node) const {
24            auto f = mMap.find(node);
25            if (f == mMap.end()) {
26                return mParent ? mParent->get(node) : nullptr;
27            }
28            return f->second;
29        }
30
31        void insert(const BDD node, PabloAST * stmt) {
32            mMap.emplace(node, stmt);
33        }
34    private:
35        const SubsitutionMap * const mParent;
36        boost::container::flat_map<BDD, PabloAST *> mMap;
37    };
38
39public:
40    static bool optimize(PabloFunction & function);
41protected:
42    void initialize(PabloFunction & function);
43    void eliminateLogicallyEquivalentStatements(PabloFunction & function);
44    void eliminateLogicallyEquivalentStatements(PabloBlock * const block, SubsitutionMap & parent);
45    void eliminateLogicallyEquivalentStatements(Statement * const stmt, SubsitutionMap & map);
46    std::pair<BDD, bool> characterize(Statement * const stmt);
47    BDD & get(const PabloAST * const expr);
48private:
49    unsigned                        mVariables;
50    CharacterizationMap             mCharacterizationMap;
51};
52
53}
54
55#endif // PABLO_BDDMINIMIZATION_H
Note: See TracBrowser for help on using the repository browser.