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

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

Back up check in. Memory leaks should be fixed.

File size: 1.9 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    static bool optimize(PabloFunction & function);
20protected:
21    inline BooleanReassociationPass() {}
22    void resolveScopes(PabloFunction & function);
23    void resolveScopes(PabloBlock &block);
24    void processScopes(PabloFunction & function);
25    void processScopes(PabloFunction & function, PabloBlock & block);
26    void processScope(PabloFunction &, PabloBlock & block);
27    void summarizeAST(PabloBlock & block, Graph & G, Map & M) const;
28    static void summarizeGraph(const PabloBlock & block, Graph & G, std::vector<Vertex> & mapping, Map &M);
29    void resolveUsages(const Vertex u, PabloAST * expr, PabloBlock & block, Graph & G, Map & M, const Statement * const ignoreIfThis = nullptr) const;
30    void redistributeAST(const PabloBlock & block, Graph & G, Map & M) const;
31    void rewriteAST(PabloBlock & block, Graph & G);
32    static PabloAST * createTree(PabloBlock & block, const Vertex u, Graph & G);
33    static Vertex getSummaryVertex(PabloAST * expr, Graph & G, Map & M, const PabloBlock & block);
34    static Vertex addSummaryVertex(const PabloAST::ClassTypeId typeId, Graph & G);
35private:
36    ScopeMap mResolvedScopes;
37};
38
39}
40
41#endif // BOOLEANREASSOCIATIONPASS_H
Note: See TracBrowser for help on using the repository browser.