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

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

Bug fix for Multiplexing. Added ability to set the body of a If/While? node after creation.

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);
47private:
48    unsigned                        mVariables;
49    CharacterizationMap             mCharacterizationMap;
50};
51
52}
53
54#endif // PABLO_BDDMINIMIZATION_H
Note: See TracBrowser for help on using the repository browser.