source: icGREP/icgrep-devel/icgrep/pablo/optimizers/booleanreassociationpass.h @ 4775

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

Work towards testing reassociation + multiplexing.

File size: 1.8 KB
Line 
1#ifndef BOOLEANREASSOCIATIONPASS_H
2#define BOOLEANREASSOCIATIONPASS_H
3
4#include <pablo/codegenstate.h>
5#include <boost/container/flat_set.hpp>
6#include <boost/container/flat_map.hpp>
7#include <boost/graph/adjacency_list.hpp>
8
9namespace pablo {
10
11class BooleanReassociationPass {
12public:
13    using VertexData = std::pair<PabloAST::ClassTypeId, PabloAST *>;
14    using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VertexData, PabloAST *>;
15    using Vertex = Graph::vertex_descriptor;
16    using Map = std::unordered_map<const PabloAST *, Vertex>;
17    using WrittenAt = boost::container::flat_map<const PabloAST *, unsigned>;
18    using ScopeMap = boost::container::flat_map<const PabloBlock *, Statement *>;
19
20    static bool optimize(PabloFunction & function);
21protected:
22    inline BooleanReassociationPass() {}
23    void resolveScopes(PabloFunction & function);
24    void resolveScopes(PabloBlock &block);
25    void processScopes(PabloFunction & function);
26    void processScopes(PabloFunction & function, PabloBlock & block);
27    void processScope(PabloFunction &, PabloBlock & block);
28    void summarizeAST(PabloBlock & block, Graph & G) const;
29    static void summarizeGraph(const PabloBlock & block, Graph & G, std::vector<Vertex> & mapping);
30    void resolveUsages(const Vertex u, PabloAST * expr, PabloBlock & block, Graph & G, Map & M, Statement * ignoreIfThis = nullptr) const;
31    void redistributeAST(const PabloBlock & block, Graph & G) const;
32    void rewriteAST(PabloBlock & block, Graph & G);
33    static PabloAST * createTree(PabloBlock & block, const Vertex u, Graph & G, const WrittenAt & writtenAt);
34    static Vertex getSummaryVertex(PabloAST * expr, Graph & G, Map & M, const PabloBlock & block);
35private:
36    ScopeMap mResolvedScopes;
37};
38
39}
40
41#endif // BOOLEANREASSOCIATIONPASS_H
Note: See TracBrowser for help on using the repository browser.